@coingecko/cryptoformat

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

Javascript library to format and display cryptocurrencies and fiat

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Known Issues
  4. Development
  5. Deployment
  6. File Sturcture

Cryptoformat

npm version Build Status License: MIT

cryptoformat is used by CoinGecko (https://www.coingecko.com) to format crypto and fiat values.

Often an altcoin can be worth much less than $0.01 USD, and thus we need to format this value by providing more decimal places in the formatting to prevent losing precious information.

cryptoformat also tries to handle different locales and currency formatting by deferring the work to the browser's Intl.NumberFormat. If Intl.NumberFormat is not supported by the browser, cryptoformat provides a primitive fallback for currency display.

Install

npm i @coingecko/cryptoformat

Usage

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 tries to cache formatters for reuse internally. If same locale and currency is used, the cached formatter will be used.

Known Issues

  1. Intl.NumberFormat does not always behave consistently across browsers. cryptoformat does some manual overrides in order to ensure that "MYR123.00" is displayed as "RM123.00", for example.
  2. Given that country detection for locale is quite hard to do, e.g. "en-MY", cryptoformat does not try to do country sniffing. It is the responsibility of the caller to provide that if possible, but providing only "en" should also work for the most part, but not perfectly: users in different regions may expect a different formatting for the same language.

Development

Deployment

npm run build && npm run submit

File Sturcture

|- 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 library to format and display cryptocurrencies and 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 和提交记录判断。