The `currency-formatter` package is a JavaScript utility designed to format and unformat monetary values based on specified currency codes or locale settings. It is currently at version 1.5.9. The library's own maintainers strongly recommend against its use for most contemporary applications, advocating instead for the native JavaScript `Intl.NumberFormat` API, which offers superior and more up-to-date internationalization capabilities in modern browsers and Node.js environments. This library primarily serves as a compatibility layer for legacy contexts, such as very old browsers lacking `Intl` support, or specific Node.js setups that do not include `full-icu` data. Its release cadence is slow, and its active development appears to have ceased in favor of native solutions. It differentiates itself by providing a consistent API for environments where `Intl.NumberFormat` is unavailable or undesirable, internally leveraging the `accounting.js` library for its core formatting logic.
npm install currency-formatterVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic currency formatting by code and locale, retrieving currency information, and unformatting monetary strings using the CommonJS API.
Migrate currency formatting logic to `new Intl.NumberFormat(locale, options).format(value)` for robust internationalization. Consider polyfilling `Intl.js` for environments that absolutely require support for older browsers.
Before adding this dependency, verify the `Intl.NumberFormat` support in your target browsers and Node.js versions (e.g., via `caniuse.com`). If support is adequate, remove `currency-formatter`.
Choose a single, consistent approach for currency formatting across your application. For new projects and modern environments, `Intl.NumberFormat` is the recommended standard. For legacy support, ensure thorough testing with `currency-formatter`.
Always provide the correct `code` or `locale` option to `currencyFormatter.unformat()` that corresponds to the format of the string being parsed. Test thoroughly with various locale-specific inputs.
Use the CommonJS `require` syntax: `const currencyFormatter = require('currency-formatter');`.For modern applications, transition to `Intl.NumberFormat` for accurate and up-to-date internationalization. If `currency-formatter` must be used, ensure `code` and `locale` options are precisely configured and thoroughly test all target currencies/locales.
Evaluate your project's `Intl.NumberFormat` support requirements. If modern browser/Node.js support is sufficient, remove `currency-formatter` and use native APIs. For legacy support, consider conditional loading or a more granular polyfill.