密码格式
cryptoformat 由 CoinGecko 使用 (https://www.coingecko.com (中文(简体) )用于格式化加密和微分值.
代币的价值往往会大大低于0.01美元,因此我们需要通过在格式上提供更多的小数位来格式化这一数值,以防止失去宝贵信息.
cryptoformat 并尝试处理不同的地块和货币格式, 将工作交由浏览器处理 Intl.NumberFormat如果 Intl.NumberFormat 浏览器不支持, cryptoformat 为货币显示提供了原始倒计时.
安装
npm i @coingecko/cryptoformat
使用量
import { formatCurrency } from "@coingecko/cryptoformat";
formatCurrency(123, "USD", "en");
// "$123.00"
formatCurrency(0.00123, "USD", "en");
// "$0.00123000"
// Provide raw = true to remove formatting and symbol
formatCurrency(0.00123, "USD", "en", true);
// "0.00123000"
formatCurrency(123400, "IDR", "id");
// "Rp123.400"
formatCurrency(123400, "EUR", "de");
// "123.400 €"
// Provide noDecimal = true to explicitly remove decimal for numbers above > 1.0
formatCurrency(4000.23, "USD", "en", false, true);
// "$4,000"
// Provide number of decimal places or significant figures
formatCurrency(1.234, "USD", "en", false, { decimalPlaces: 2 });
// "$1.23"
formatCurrency(1234, "USD", "en", false, { significantFigures: 2 });
// "$1,200"
// Provide number of significant figures only up to specified number of decimal places
formatCurrency(0.1234, "USD", "en", false, { decimalPlaces: 2, significantFigures: 3 });
// "$0.12"
cryptoformat 尝试缓存格式化器进行内部再利用。 如果使用相同的地块和货币,则使用被缓存的物料.
已知问题
Intl.NumberFormat并不总是在浏览器之间保持一致.cryptoformat执行一些手动覆盖,以确保“MYR123.00”显示为“RM123.00”.- 鉴于乡下居民的检测相当困难,例如"在MY",
cryptoformat并不尝试在乡下嗅探。 打电话者有责任提供,如果可能的话,但只提供"en"同样大多会有效,但并不完美:不同地区的用户可能期望同一语言有不同的格式.
发展
部署
npm run build && npm run submit
文件缓冲
|- lib
|- index.js (Build with babel)
|- src
- index.js (Main Code)
- index.d.ts (Types for TypeScript)
- test.js (Test with Jest)