# @coingecko/cryptoformat 中文文档

规范地址：https://npmcn.com/package/%40coingecko/cryptoformat/

版本：0\.8\.3
npm 元数据更新时间：2026-07-15T05:47:36.024Z
中文译文更新时间：2026-11-10T10:36:13.448Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40coingecko/cryptoformat
原文对照：https://npmcn.com/package/%40coingecko/cryptoformat/?lang=original
项目主页：https://github.com/coingecko/cryptoformat#readme
源码仓库：https://github.com/coingecko/cryptoformat

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：5.1 kB，3 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- Node.js 要求：\>=18
- 运行依赖：0 个
- 首次发布：2018-07-02T06:48:25.357Z
- 最新版本发布：2026-01-19T06:46:23.900Z
- 近 30 天下载量：5129（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：41（近 12 个月 1 个）

## 中文简介

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

## 安装

```sh
npm install @coingecko/cryptoformat
```

也可以使用：`pnpm add @coingecko/cryptoformat`、`yarn add @coingecko/cryptoformat`、`bun add @coingecko/cryptoformat`

## README

# 密码格式

[![npm version](https://badge.fury.io/js/%40coingecko%2Fcryptoformat.svg)](https://badge.fury.io/js/%40coingecko%2Fcryptoformat) [![Build Status](https://travis-ci.org/coingecko/cryptoformat.svg?branch=master)](https://travis-ci.org/coingecko/cryptoformat) ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)

`cryptoformat` 由 CoinGecko 使用 ([https://www.coingecko.com (中文(简体) )](https://www.coingecko.com/)用于格式化加密和微分值.

代币的价值往往会大大低于0.01美元,因此我们需要通过在格式上提供更多的小数位来格式化这一数值,以防止失去宝贵信息.

`cryptoformat` 并尝试处理不同的地块和货币格式, 将工作交由浏览器处理 [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)如果 `Intl.NumberFormat` 浏览器不支持, `cryptoformat` 为货币显示提供了原始倒计时.

## 安装

```
npm i @coingecko/cryptoformat
```

## 使用量

```js
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 是什么？

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 和提交记录判断。

