@coingecko/cryptoformat

中文文档
0.8.3发布于 2026/01/19MITES Module零依赖近 30 天下载 5129

Javascript 库用于格式化并显示加密和 fiat

中文使用文档
文档目录6 节
  1. 安装
  2. 使用量
  3. 已知问题
  4. 发展
  5. 部署
  6. 文件缓冲

密码格式

npm version Build Status License: MIT

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 尝试缓存格式化器进行内部再利用。 如果使用相同的地块和货币,则使用被缓存的物料.

已知问题

  1. Intl.NumberFormat 并不总是在浏览器之间保持一致. cryptoformat 执行一些手动覆盖,以确保“MYR123.00”显示为“RM123.00”.
  2. 鉴于乡下居民的检测相当困难,例如"在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)

版本与发布记录

@coingecko/cryptoformat 共发布 41 个版本,首次发布于 2018/07/02;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.8.3latest2026/01/199 个月前
0.8.22024/07/152 年前
0.8.12024/01/232 年前
0.8.02023/12/192 年前
0.7.02023/11/013 年前
0.6.12023/11/013 年前

关于 @coingecko/cryptoformat 的常见问题

@coingecko/cryptoformat 是什么?

Javascript 库用于格式化并显示加密和 fiat

如何安装 @coingecko/cryptoformat?

在项目目录运行 npm install @coingecko/cryptoformat,或使用 pnpm add / yarn add / bun add。

@coingecko/cryptoformat 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/coingecko__cryptoformat 是否存在。

@coingecko/cryptoformat 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@coingecko/cryptoformat 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@coingecko/cryptoformat 可以商用吗?

@coingecko/cryptoformat 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@coingecko/cryptoformat 的下载量有多少?

根据 npm 官方下载统计,@coingecko/cryptoformat 在 2026/10/11 – 2026/11/09 这 30 天内被下载 5,129 次,日均约 171 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@coingecko/cryptoformat 还在维护吗?

最新版本 0.8.3 发布于 2026/01/19(9 个月前);至今共发布 41 个版本,其中过去 12 个月发布了 1 个;首次发布于 2018/07/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。