{"id":10704,"library":"currency-formatter","title":"Currency Formatter","description":"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.","status":"deprecated","version":"1.5.9","language":"javascript","source_language":"en","source_url":"https://github.com/smirzaei/currency-formatter","tags":["javascript","format","currency","money"],"install":[{"cmd":"npm install currency-formatter","lang":"bash","label":"npm"},{"cmd":"yarn add currency-formatter","lang":"bash","label":"yarn"},{"cmd":"pnpm add currency-formatter","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally by currency-formatter for core formatting logic.","package":"accounting","optional":false}],"imports":[{"note":"This library is primarily CommonJS. While bundlers might allow `import`, `require` is the intended and most reliable way to import.","wrong":"import currencyFormatter from 'currency-formatter';","symbol":"currencyFormatter","correct":"const currencyFormatter = require('currency-formatter');"},{"note":"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.","wrong":"import { format } from 'currency-formatter';","symbol":"format","correct":"const { format } = require('currency-formatter'); // Or currencyFormatter.format(...)"},{"note":"Similar to `format`, `findCurrency` is a method on the default CommonJS export. Prefer accessing it via the default `currencyFormatter` object.","wrong":"import { findCurrency } from 'currency-formatter';","symbol":"findCurrency","correct":"const { findCurrency } = require('currency-formatter'); // Or currencyFormatter.findCurrency(...)"}],"quickstart":{"code":"const currencyFormatter = require('currency-formatter');\n\n// Format a number by currency code\nlet formattedUSD = currencyFormatter.format(1000000, { code: 'USD' });\nconsole.log(`Formatted USD: ${formattedUSD}`); // Expected: $1,000,000.00\n\n// Format a number by locale\nlet formattedEUR_de = currencyFormatter.format(1000000, { locale: 'de-DE' });\nconsole.log(`Formatted EUR (de-DE): ${formattedEUR_de}`); // Expected: 1.000.000,00 €\n\n// Get currency information\nlet usdInfo = currencyFormatter.findCurrency('USD');\nconsole.log('USD Currency Info:', usdInfo);\n/* Expected: {\n *   code: 'USD',\n *   symbol: '$',\n *   thousandsSeparator: ',',\n *   decimalSeparator: '.',\n *   symbolOnLeft: true,\n *   spaceBetweenAmountAndSymbol: false,\n *   decimalDigits: 2\n * } */\n\n// Unformat a monetary string\nlet unformattedUSD = currencyFormatter.unformat('$1,000,000.00', { code: 'USD' });\nconsole.log(`Unformatted USD: ${unformattedUSD}`); // Expected: 1000000\n\nlet unformattedEUR = currencyFormatter.unformat('1.000.000,00 €', { locale: 'de-DE' });\nconsole.log(`Unformatted EUR: ${unformattedEUR}`); // Expected: 1000000.00","lang":"javascript","description":"Demonstrates basic currency formatting by code and locale, retrieving currency information, and unformatting monetary strings using the CommonJS API."},"warnings":[{"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.","message":"This 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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`.","message":"Including `currency-formatter` may unnecessarily increase your application's bundle size if your target environments already support the native `Intl.NumberFormat` API.","severity":"gotcha","affected_versions":">=1.0.0"},{"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`.","message":"Formatting 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use the CommonJS `require` syntax: `const currencyFormatter = require('currency-formatter');`.","cause":"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.","error":"TypeError: currencyFormatter.format is not a function"},{"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.","cause":"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.","error":"My currency formatting is incorrect or doesn't match native browser behavior for certain locales/currencies."},{"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.","cause":"The library is included in the production build even if its functionality is redundant because the target environments natively support `Intl.NumberFormat`.","error":"My JavaScript bundle size increased significantly after adding currency-formatter."}],"ecosystem":"npm"}