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

tiny-number-converter

v1.1.6

Published

簡易的數值轉換庫

Downloads

1

Readme

tiny-number-converter

Little library for numerical format conversion.

npm version

Usage

/* es6 引入 */
import numberFormat from 'tiny-number-converter';

/* 方法函式 */
numberFormat(number[, formatStr]);

/* 建構式方式 */
var myNumber = new numberFormat(number);
/* 印出轉換結果 */
myNumber.value();
/* 變更轉換格式,並印出結果 */
myNumber.format(newFormatStr);

| 參數 | 型別 | 必填 | 說明 | |----|----|----|----| | number | number | Y | 變更的數值對象 | | formatStr | string | N | 要轉換的格式描述預設值為1.2cr,詳情請參閱 Patterns |

Patterns

| 格式 | 名稱 | 說明 | |----|---------------|------------------------------------------------------| | /d | Integer | 取整數位數,不足位補零,無條件捨去,空字串回傳空字串 | | ./d | Decimal | 取小數點後位數,無條件捨去 | | r | Rounding | 四捨五入 | | c | Comma | 加上逗號 | | k | Kilo | 以千為單位取值 | | m | Million | b | Billion | 以十億為單位取值 | | g | Greatest | 自動換算最大單位,輸出包含單位 | | a | All | 換算最大之後的所有單位 | | [] | Output | 輸出[]裡面文字 | | () | Grouping | 群組 |

Example

Integer

| number | formatStr | return | | | -------- | -------- | -------- |-------- | | 123456.789 | 0 | 123456 |最小位數為0| |0|0|''|最小位數為0,若輸出為零就不顯示| |123456.789| ''| ''|空字串回傳空| |0| 1| 0|不足位補零| |123456.789|3|123456|最小位數為3,足位顯示全部| |123456.789| 8|00123456|最小位數為8,不足位補零| |123456.789|-3|456|取後面三碼|

Decimal

| number | formatStr | return | | | -------- | -------- | -------- |-------- | |123456.789|.0|.789|取全部小數| |123456.789|.2|.78|取到小數後兩位| |123456.789|.4|.7890|取小數四位,不足位補零| |123.456| ''| ''|空字串回傳空| |123.456|.-4| ''|錯誤格式|

Rounding

| number | formatStr| return | | | -------- | -------- | -------- |-------- | |456.78|0.1r| 456.8|取到小數後一位,並四捨五入| |123456.789|0r| 123457|取整數,並四捨五入| |-456.78|0r| -457|負數的實例|

Comma

| number | formatStr| return | | | -------- | -------- | -------- |-------- | |123456.789|0c|123,456|使用千分符| |123456.789|7c|0,123,456|| |123456.789|-4.2c|3,456.78||

Kilo, Million, Billion

| number | formatStr| return | | | -------- | -------- | -------- |-------- | |123456.789|0k|123|轉換到千位數| |123456789.123|0.2k|123456.78|| |123456789|-4ckr|3,457|| |123456.789|k||沒有給位數,就不處理| |123456.789|0.4m|0.1234|轉換到百萬位數| |123|0.8m|0.00012300|| |1234567890000|0bc|1,234|轉換到十億位數| |123000|0.8b|0.00012300||

Greatest

| number | formatStr| return | | | -------- | -------- | -------- |-------- | |123456.789|0g|123K|最大單位為千位數| |100|0g||最小單位為零:結果為零,回傳空| |123456.789|0.0g|123.456789K|| |0.789|0.0g|0.000789K|| |123456.789|g||沒有給位數,就不處理| |123456789.123|2.3g|123.456M|| |123456789.123|5.3gr|00123.457M|| |1234567890000.123|0.3grc|1,234.568B||

All

| number | formatStr| return | | | -------- | -------- | -------- |-------- |123456789.123|a|123M 456K|| |123000456789.123|a|123B 0M 456K|| |100|a|0K|顯示到最小單位|

Output

| number | formatStr| return | | -------- | -------- | -------- | |123456789.123|[NTD: ]0k[$]|NTD: 123456$| |1123456.789|1.4ckm[km]|1,123.4567km| |123456.789|-4.2c[(千)]|3,456.78(千)| |123456789|[Amount: $]12c|Amount: $000,123,456,789|

Grouping

| number | formatStr| return || | -------- | -------- | -------- |-- | |1234567.89|(0m)M & (0k)K|1M & 1234K|| |123456.789|(1m)M,(0k)K|0M,123K|| |1234567.89|(-3m)M,(-3k)K,(-3.2)|1M,234K,567.89|| |123456789.123|(0mM)[k](0k)|123[k]123456|| |1000|[ABC](0k)|[ABC]1|群組外視為字串處理| |1000|ABC(0k)|ABC1||