@depay/local-currency

中文文档
3.8.2发布于 2024/09/11MITESM + CJS零依赖近 30 天下载 4406

JavaScript library that detects user's local currency and provides functionalities to convert between multiple currencies.

原始使用文档
文档目录11 节
  1. Quickstart
  2. Functionalities
  3. new Currency
  4. toString
  5. fromUSD
  6. rate
  7. getCode
  8. set currency globally
  9. Development
  10. Get started
  11. Release

Quickstart

yarn add @depay/local-currency

or

npm install --save @depay/local-currency
import { Currency } from '@depay/local-currency'

let currency = new Currency({ amount: 20 })
currency.toString()
// €22.32

Functionalities

new Currency

Creates an instance of Currency

let currency = new Currency({ amount: 20 })

amount sets the amount you want to convert into a currency string.

timeZone will be automatically detected by the client, but can be provided to:

let currency = new Currency({ amount: 20, timeZone: 'Europe/Berlin' })

toString

Converts a currency string into a formatted string:

let currency = new Currency({ amount: 20 })
currency.toString()
// €22.32

options: accepts options object that will be forwarded to Intl.NumberFormat

new LocalCurrency.Currency({ amount: 20 }).toString({ minimumFractionDigits: 0 })
// $20

fromUSD

Converts USD into local currency:

let currency = await Currency.fromUSD({ amount: 20 })
currency.toString()
// €16.88

rate

Gets rate for given from and to:

let rate = await Currency.rate({ from: 'EUR', to: 'GBP' })
// 1.1585365853658536

getCode

Gives you the local currency code:

Currency.getCode()
// EUR

set currency globally

e.g. in tests etc.:

window._LocalCurrencyCode = 'EUR'

Development

Get started

yarn install
yarn dev

Release

npm publish

版本与发布记录

@depay/local-currency 共发布 20 个版本,首次发布于 2021/11/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.8.2latest2024/09/112 年前
3.8.12024/09/092 年前
3.8.02023/10/093 年前
3.7.02023/10/093 年前
3.6.12023/06/023 年前
3.6.02022/12/173 年前

关于 @depay/local-currency 的常见问题

@depay/local-currency 是什么?

JavaScript library that detects user's local currency and provides functionalities to convert between multiple currencies.

如何安装 @depay/local-currency?

在项目目录运行 npm install @depay/local-currency,或使用 pnpm add / yarn add / bun add。

@depay/local-currency 支持 TypeScript 吗?

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

@depay/local-currency 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@depay/local-currency 需要什么版本的 Node.js?

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

@depay/local-currency 可以商用吗?

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

@depay/local-currency 的下载量有多少?

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

@depay/local-currency 还在维护吗?

最新版本 3.8.2 发布于 2024/09/11(2 年前);至今共发布 20 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/11/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。