Registry / serialization / currency-formatter

currency-formatter

JSON →
library1.5.9jsnpmunverified

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-formatter
INSTALL
IMPORT
SIG · CURRENCY-FORMATTER
C
currency-formatter
serializationjavascriptv1.5.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

currencyFormatter
const currencyFormatter = require('currency-formatter');
import currencyFormatter from 'currency-formatter';
This library is primarily CommonJS. While bundlers might allow `import`, `require` is the intended and most reliable way to import.
format
const { format } = require('currency-formatter'); // Or currencyFormatter.format(...)
import { format } from 'currency-formatter';
The `format` function is a method on the default export. Destructuring from `require` works, but directly accessing `currencyFormatter.format` is also common. ESM named imports might fail without proper transpilation.
findCurrency
const { findCurrency } = require('currency-formatter'); // Or currencyFormatter.findCurrency(...)
import { findCurrency } from 'currency-formatter';
Similar to `format`, `findCurrency` is a method on the default CommonJS export. Prefer accessing it via the default `currencyFormatter` object.

Demonstrates basic currency formatting by code and locale, retrieving currency information, and unformatting monetary strings using the CommonJS API.

const currencyFormatter = require('currency-formatter'); // Format a number by currency code let formattedUSD = currencyFormatter.format(1000000, { code: 'USD' }); console.log(`Formatted USD: ${formattedUSD}`); // Expected: $1,000,000.00 // Format a number by locale let formattedEUR_de = currencyFormatter.format(1000000, { locale: 'de-DE' }); console.log(`Formatted EUR (de-DE): ${formattedEUR_de}`); // Expected: 1.000.000,00 € // Get currency information let usdInfo = currencyFormatter.findCurrency('USD'); console.log('USD Currency Info:', usdInfo); /* Expected: { * code: 'USD', * symbol: '$', * thousandsSeparator: ',', * decimalSeparator: '.', * symbolOnLeft: true, * spaceBetweenAmountAndSymbol: false, * decimalDigits: 2 * } */ // Unformat a monetary string let unformattedUSD = currencyFormatter.unformat('$1,000,000.00', { code: 'USD' }); console.log(`Unformatted USD: ${unformattedUSD}`); // Expected: 1000000 let unformattedEUR = currencyFormatter.unformat('1.000.000,00 €', { locale: 'de-DE' }); console.log(`Unformatted EUR: ${unformattedEUR}`); // Expected: 1000000.00
Debug
Known issues
breakingThis library is explicitly deprecated by its own maintainers. The README strongly advises against its use for most modern applications, recommending the native `Intl.NumberFormat` API instead.
fix
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.
affects: >=1.0.0
gotchaIncluding `currency-formatter` may unnecessarily increase your application's bundle size if your target environments already support the native `Intl.NumberFormat` API.
fix
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`.
affects: >=1.0.0
gotchaFormatting results from `currency-formatter` may differ from those produced by the native `Intl.NumberFormat` API due to different underlying implementations and locale data, potentially leading to inconsistent UI.
fix
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`.
affects: >=1.0.0
gotchaThe `unformat` function's behavior relies heavily on the provided `code` or `locale` parameters to correctly parse monetary strings, and may produce unexpected results if these do not match the input string's format.
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: currencyFormatter.format is not a function
Attempting to use an ES module default import (e.g., `import currencyFormatter from 'currency-formatter'`) in an environment or bundler configuration where the `currency-formatter` package is treated as a CommonJS module without a compatible default export for ESM.
fix
Use the CommonJS `require` syntax: `const currencyFormatter = require('currency-formatter');`.
My currency formatting is incorrect or doesn't match native browser behavior for certain locales/currencies.
Discrepancies between `currency-formatter`'s internal locale data or formatting logic and the more current/standardized behavior of the `Intl.NumberFormat` API, or incorrect `code`/`locale` options provided.
fix
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.
My JavaScript bundle size increased significantly after adding currency-formatter.
The library is included in the production build even if its functionality is redundant because the target environments natively support `Intl.NumberFormat`.
fix
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.
Upgrade
Version history
1.5.9latest on npm
Audit
Dependencies
accountingrequiredUsed internally by currency-formatter for core formatting logic.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
currency-formatter — npm install currency-formatter · libregistry