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 🙏

© 2024 – Pkg Stats / Ryan Hefner

numvert

v0.2.2

Published

数字转换插件

Downloads

163

Readme

numvert

基于 numeral 进行封装, 增加更多转换格式

import numvert from 'numvert';


numvert(1000).format('0,0');
// '1,000'

转换

数字

| Number | Format | String | | :--------- | :----------- | :------------ | | 10000 | '0,0.0000' | 10,000.0000 | | 10000.23 | '0,0' | 10,000 | | 10000.23 | '+0,0' | +10,000 | | -10000 | '0,0.0' | -10,000.0 | | 10000.1234 | '0.000' | 10000.123 | | 100.1234 | '00000' | 00100 | | 1000.1234 | '000000,0' | 001,000 | | 10 | '000.00' | 010.00 | | 10000.1234 | '0[.]00000' | 10000.12340 | | -10000 | '(0,0.0000)' | (10,000.0000) | | -0.23 | '.00' | -.23 | | -0.23 | '(.00)' | (.23) | | 0.23 | '0.00000' | 0.23000 | | 0.23 | '0.0[0000]' | 0.23 | | 1230974 | '0.0a' | 1.2m | | 1460 | '0 a' | 1 k | | -104000 | '0a' | -104k | | 1000 | '0r' | 1000 | | 12345 | '0.0r' | '1.2万' | | 123456789 | '0.00r' | '1.23亿' | | 1 | '0o' | 1. | | 100 | '0o' | 100. |

金钱

| Number | Format | String | | :-------- | :----------- | :---------- | | 1000.234 | '$0,0.00' | $1,000.23 | | 1000.2 | '0,0[.]00 $' | 1,000.20 $ | | 1001 | '$ 0,0[.]00' | $ 1,001 | | -1000.234 | '($0,0)' | ($1,000) | | -1000.234 | '$0.00' | -$1000.23 | | 1230974 | '($ 0.00 a)' | ¥ 1.23 m | | 123123 | '0cent' | 1231 |

存储

| Number | Format | String | | :------------ | :--------- | :-------- | | 100 | '0b' | 100B | | 1024 | '0b' | 1KB | | 2048 | '0 ib' | 2 KiB | | 3072 | '0.0 b' | 3.1 KB | | 7884486213 | '0.00b' | 7.88GB | | 3467479682787 | '0.000 ib' | 3.154 TiB |

百分比

| Number | Format | String | | :---------- | :---------- | :------- | | 1 | '0%' | 100% | | 0.974878234 | '0.000%' | 97.488% | | -0.43 | '0 %' | -43 % | | 0.43 | '(0.000 %)' | 43.000 % |

时间

| Number | Format | String | | :----- | :--------- | :------- | | 25 | '00:00:00' | 0:00:25 | | 238 | '00:00:00' | 0:03:58 | | 63846 | '00:00:00' | 17:44:06 |

科学

| Number | Format | String | | :----------- | :--------- | :------- | | 1123456789 | '0,0e+0' | 1e+9 | | 12398734.202 | '0.00e+0' | 1.24e+7 | | 0.000123987 | '0.000e+0' | 1.240e-4 |

附加功能

取真实值

并非所有格式都支持

var number = numvert(1000);

var string = number.format('0,0');
// '1,000'

var value = number.value();
// 1000

计算

必要时使用,并非必须使用。

var number = numvert(1000).add(10);
// 1010

| Before | Function | After | | :----- | :------------- | :----- | | 1000 | .add(100) | 1100 | | 1100 | .subtract(100) | 1000 | | 1000 | .multiply(100) | 100000 | | 100000 | .divide(100) | 1000 |

设置

设置值,字面意思

var number = numvert().set(1000);

var value = number.value();
// 1000

取差

用于获取一个数字和numvert对象的差

var number = numvert(1000),
    value = 100;

var difference = number.difference(value);
// 900

克隆

对于numvert产生的任何对象都可以进行复制

var a = numvert(1000);
var b = numvert(a);
var c = a.clone();

var aVal = a.set(2000).value();
// 2000

var bVal = b.value();
// 1000

var cVal = c.add(10).value();
// 1010