npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ricardowdl/number-input

v1.0.0

Published

一个支持千分位货币格式的 React 数字输入框组件

Readme

NumberInput

一个支持千分位货币格式的 React 数字输入框组件。

特性

  • ✅ 支持千分位货币格式格式化
  • ✅ 可选的格式化功能(通过 props 控制)
  • ✅ 支持小数点和负数
  • ✅ 支持最小值和最大值限制
  • ✅ TypeScript 支持
  • ✅ 完全可自定义样式

安装

npm install @your-username/number-input

或使用 yarn:

yarn add @your-username/number-input

使用方法

基础用法

import NumberInput from '@your-username/number-input';

function App() {
  const [value, setValue] = useState<number | null>(null);

  return (
    <NumberInput
      value={value}
      onChange={setValue}
      placeholder="请输入数字"
    />
  );
}

启用千分位格式

import NumberInput from '@your-username/number-input';

function App() {
  const [value, setValue] = useState<number | null>(null);

  return (
    <NumberInput
      value={value}
      onChange={setValue}
      formatCurrency={true}
      placeholder="请输入金额"
    />
  );
}

API

Props

| 属性 | 类型 | 默认值 | 说明 | |------|------|--------|------| | value | number \| string \| null | - | 输入框的值 | | onChange | (value: number \| null) => void | - | 值变化时的回调函数 | | formatCurrency | boolean | false | 是否开启千分位货币格式 | | placeholder | string | '请输入数字' | 输入框占位符 | | className | string | '' | 自定义 CSS 类名 | | disabled | boolean | false | 是否禁用 | | min | number | - | 最小值限制 | | max | number | - | 最大值限制 | | onBlur | (e: FocusEvent<HTMLInputElement>) => void | - | 失去焦点时的回调 |

示例

带范围限制的输入框

<NumberInput
  value={value}
  onChange={setValue}
  min={0}
  max={1000000}
  formatCurrency={true}
/>

自定义样式

<NumberInput
  value={value}
  onChange={setValue}
  className="custom-input-class"
  formatCurrency={true}
/>

工作原理

  • 普通模式 (formatCurrency={false}): 输入数字后直接显示,不进行格式化
  • 千分位模式 (formatCurrency={true}):
    • 输入时显示纯数字以便编辑
    • 失去焦点时自动格式化为千分位格式(如:1,234.56)
    • 获得焦点时自动转换为纯数字以便编辑

开发

# 构建包
npm run build:package

# 开发 Next.js 应用
npm run dev

License

MIT