{"_id":"locale-currency","_rev":"9-316f7e1b51508b88ab3d06d330b457ad","name":"locale-currency","dist-tags":{"latest":"1.1.0"},"versions":{"0.0.1":{"name":"locale-currency","version":"0.0.1","author":{"name":"Thomas Deegan","email":"tadeegan@gmail.com"},"license":"BSD-2-Clause","_id":"locale-currency@0.0.1","maintainers":[{"name":"tadeegan","email":"tadeegan@gmail.com"}],"homepage":"https://github.com/tadeegan/locale-currency#readme","bugs":{"url":"https://github.com/tadeegan/locale-currency/issues"},"dist":{"shasum":"c9e15a22ff575b4b4bb947a4bf92ac236bd1fe9b","tarball":"https://registry.npmjs.org/locale-currency/-/locale-currency-0.0.1.tgz","integrity":"sha512-r4gOinchOcF0U4NXkG4F70fB/3vqTdmRi7dLAZQL6pAMTZwbL6sXMG/QePW3lIBmQ3XavblrZkoSmJg4s8h+yQ==","signatures":[{"sig":"MEQCIAlo5s8fOuEuCawxArVm6C0cSSR2hb+cB1rmfGs+4fVRAiA5LO8JlnSfUfI5gIGwW5olXJv1slQpCO5/cF/y9KXWkw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"c9e15a22ff575b4b4bb947a4bf92ac236bd1fe9b","gitHead":"830ea1bf233daf20cf55e250095a68d8b8c53820","scripts":{"test":"node test.js"},"_npmUser":{"name":"tadeegan","email":"tadeegan@gmail.com"},"repository":{"url":"git+https://github.com/tadeegan/locale-currency.git","type":"git"},"_npmVersion":"3.8.5","description":"A map of i18n country codes to ISO 4217 currency codes.  Originally generated from the output of java.util.Currency.getInstance(locale)","directories":{},"_nodeVersion":"0.10.18","dependencies":{},"_npmOperationalInternal":{"tmp":"tmp/locale-currency-0.0.1.tgz_1459721025565_0.8142437166534364","host":"packages-12-west.internal.npmjs.com"}},"0.0.2":{"name":"locale-currency","version":"0.0.2","author":{"name":"Thomas Deegan","email":"tadeegan@gmail.com"},"license":"BSD-2-Clause","_id":"locale-currency@0.0.2","maintainers":[{"name":"tadeegan","email":"tadeegan@gmail.com"}],"homepage":"https://github.com/tadeegan/locale-currency#readme","bugs":{"url":"https://github.com/tadeegan/locale-currency/issues"},"dist":{"shasum":"e2c90607563ce47a59f9559e45a70e24e4db4b6d","tarball":"https://registry.npmjs.org/locale-currency/-/locale-currency-0.0.2.tgz","integrity":"sha512-5uUCVWBhixSV9x48yONxyGaW7YNGwFqM3f0ue1V+GbcHXGfOLKP+2HrwSFxkQ59V7cgcxahkRLD2Lw/CRfBJAQ==","signatures":[{"sig":"MEYCIQCl5BeO4O0ji08xzt2PqRL9mL9N3QUUZ85WglwEMIeDwwIhAJOwYuAa5uU1D04XHlVpRAVeX5gPsG3G0GE0uXvhuIOl","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","types":"./index.d.ts","_shasum":"e2c90607563ce47a59f9559e45a70e24e4db4b6d","gitHead":"e3573c18e6a9032de036f14b493fce4cd6eaaa41","scripts":{"test":"node test.js"},"_npmUser":{"name":"tadeegan","email":"tadeegan@gmail.com"},"repository":{"url":"git+https://github.com/tadeegan/locale-currency.git","type":"git"},"_npmVersion":"4.0.5","description":"A map of i18n country codes to ISO 4217 currency codes.  Originally generated from the output of java.util.Currency.getInstance(locale)","directories":{},"_nodeVersion":"7.4.0","dependencies":{},"_npmOperationalInternal":{"tmp":"tmp/locale-currency-0.0.2.tgz_1510513158571_0.3356250743381679","host":"s3://npm-registry-packages"}},"0.0.4":{"name":"locale-currency","version":"0.0.4","author":{"name":"Thomas Deegan","email":"tadeegan@gmail.com"},"license":"BSD-2-Clause","_id":"locale-currency@0.0.4","maintainers":[{"name":"tadeegan","email":"tadeegan@gmail.com"}],"homepage":"https://github.com/tadeegan/locale-currency#readme","bugs":{"url":"https://github.com/tadeegan/locale-currency/issues"},"dist":{"shasum":"f432aa7283c596f6fbd3354376ad92348228e507","tarball":"https://registry.npmjs.org/locale-currency/-/locale-currency-0.0.4.tgz","fileCount":8,"integrity":"sha512-S3pRVxU7xZDFlN4DkvLChQf8e1xm39XD6gkiWk1GI7nP3P7VMXHTWD/ZLLr13rAKNRpAeNCgTTMMNxEG8GZYRQ==","signatures":[{"sig":"MEQCIHfcqtDCGe0erzIJqGUtj2hzkSNIGl/rXSZIBJbXwTJ3AiAROom383rhc0U/msAGTOg4weB7D9geBHkPl7p6FzYMow==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":7857},"main":"index.js","types":"./index.d.ts","gitHead":"7be9109b9a85be6e722c530d104c3edc6da01588","scripts":{"test":"node test.js"},"_npmUser":{"name":"tadeegan","email":"tadeegan@gmail.com"},"repository":{"url":"git+https://github.com/tadeegan/locale-currency.git","type":"git"},"_npmVersion":"10.9.0","description":"A map of i18n country codes to ISO 4217 currency codes.  Originally generated from the output of java.util.Currency.getInstance(locale)","directories":{},"_nodeVersion":"23.3.0","dependencies":{},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/locale-currency_0.0.4_1736202605816_0.3382877202481953","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"locale-currency","version":"1.0.0","keywords":["locale","currency","i18n","internationalization","BCP 47","ISO 4217","ISO 3166-1","country code"],"author":{"name":"Thomas Deegan","email":"tadeegan@gmail.com"},"license":"BSD-2-Clause","_id":"locale-currency@1.0.0","maintainers":[{"name":"tadeegan","email":"tadeegan@gmail.com"}],"homepage":"https://github.com/tadeegan/locale-currency#readme","bugs":{"url":"https://github.com/tadeegan/locale-currency/issues"},"dist":{"shasum":"c45b0e0b2535b40aab7c140a90d7b96177ba91af","tarball":"https://registry.npmjs.org/locale-currency/-/locale-currency-1.0.0.tgz","fileCount":6,"integrity":"sha512-OPw/KpjqAQdk36fbBHzJxPVpFx7DGU4jFYjmJoinkvbgS/QeKtsykiXszgS/EB458eieVppo/gbP1CbtJN4E9g==","signatures":[{"sig":"MEUCIQCiXvIjQWNV8i8c3KzsBkYB0U9tTRCHCuYyKCHK8OZchgIgCAEsxOaNq5F7Gq3tqFcmVWnmnSnM3AWF9cbMy8luF8A=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10228},"main":"index.js","type":"module","types":"./index.d.ts","engines":{"node":">=14.0.0"},"exports":{".":{"types":"./index.d.ts","import":"./index.js","require":"./index.js"}},"gitHead":"8a201232ff33b660969f300e9b4a30e5abe076e7","scripts":{"test":"node test.js && npm run test:types && npm run test:cjs","test:cjs":"node test-cjs.cjs","test:types":"tsc --noEmit"},"_npmUser":{"name":"tadeegan","email":"tadeegan@gmail.com"},"repository":{"url":"git+https://github.com/tadeegan/locale-currency.git","type":"git"},"_npmVersion":"11.6.0","description":"A map of locale codes to ISO 4217 currency codes. Supports BCP 47, i18n, and ISO 3166-1 alpha-2 formats.","directories":{},"_nodeVersion":"24.8.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.2","@types/node":"^24.6.0"},"_npmOperationalInternal":{"tmp":"tmp/locale-currency_1.0.0_1759261934658_0.9049651192810413","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"locale-currency","version":"1.0.1","keywords":["locale","currency","i18n","internationalization","BCP 47","ISO 4217","ISO 3166-1","country code"],"author":{"name":"Thomas Deegan","email":"tadeegan@gmail.com"},"license":"BSD-2-Clause","_id":"locale-currency@1.0.1","maintainers":[{"name":"tadeegan","email":"tadeegan@gmail.com"}],"homepage":"https://github.com/tadeegan/locale-currency#readme","bugs":{"url":"https://github.com/tadeegan/locale-currency/issues"},"dist":{"shasum":"713e217738443cfe416d0b5e6e40b16cf7bb9804","tarball":"https://registry.npmjs.org/locale-currency/-/locale-currency-1.0.1.tgz","fileCount":6,"integrity":"sha512-9CypbbT7EsxQ6Ix2hZkjWoTMsENq3JziVdQDi9EQY0KMOKXjp35SCMH8knZyM+GYux9AWvVJ3OHLZ/SRuQOPzQ==","signatures":[{"sig":"MEYCIQDwjzfD7GIGab7LwEJUrs5mhnoxcnxkuh9nZGBoBeRY9gIhAOhUIzuj8NgsoGgqzfD/2+8OqFbZwRIl+aTvqxV1bown","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQDn96I0NiO4NDIRp130OFMCQAtJUkNC4zNfkJVo3RDuPAIgUTSR0I9ZPCeJmyayqO6I8BF6484zit9PXnKy8c9FvIs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10228},"main":"index.js","type":"module","types":"./index.d.ts","engines":{"node":">=14.0.0"},"exports":{".":{"types":"./index.d.ts","import":"./index.js","require":"./index.js"}},"gitHead":"e583f30cb25329c98ad4f9130e2e2e73cac1ddf0","scripts":{"test":"node test.js && npm run test:types && npm run test:cjs","test:cjs":"node test-cjs.cjs","test:types":"tsc --noEmit"},"_npmUser":{"name":"tadeegan","email":"tadeegan@gmail.com"},"repository":{"url":"git+https://github.com/tadeegan/locale-currency.git","type":"git"},"_npmVersion":"11.6.0","description":"A map of locale codes to ISO 4217 currency codes. Supports BCP 47, i18n, and ISO 3166-1 alpha-2 formats.","directories":{},"_nodeVersion":"24.8.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.2","@types/node":"^24.6.0"},"_npmOperationalInternal":{"tmp":"tmp/locale-currency_1.0.1_1792641234955_0.0853861590486924","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"_id":"locale-currency@1.1.0","bugs":{"url":"https://github.com/tadeegan/locale-currency/issues"},"dist":{"shasum":"d00e4051f4d818b5a5eadb7fba1caa5b7c007407","tarball":"https://registry.npmjs.org/locale-currency/-/locale-currency-1.1.0.tgz","fileCount":8,"integrity":"sha512-iUGW0j2UiNnf5r4jeBaZgnGkY0Dp8cSnbXni1UsdDpsHEi3Us6kX4GIs8Z7SxI37EgyulbTDO9TQEJU3M6vofQ==","signatures":[{"sig":"MEUCIQDxijd0/iGUPY7cxR72hFMucQzJesg8V8sSjnpyvNxiVwIgO4IOKoazZ7PYlbGCwPf8PGPK43L8i1bfGn4FAoonDCQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDeZWoNoBVZR2AI5hHdFcktMLObrd9pG4JiblqWfe/4mQIgRred209JNx0Q3h6RYOLSiODtibBrrKwyfpZ0k2Sm+us="}],"unpackedSize":16864},"main":"index.js","name":"locale-currency","type":"module","types":"./index.d.ts","author":{"name":"Thomas Deegan","email":"tadeegan@gmail.com"},"engines":{"node":">=14.0.0"},"exports":{".":{"types":"./index.d.ts","import":"./index.js","default":"./index.js"},"./decimals":{"types":"./currency-decimals.d.ts","import":"./currency-decimals.js","default":"./currency-decimals.js"},"./package.json":"./package.json"},"gitHead":"3183f3bf6b4ee2a8624808cd0f927dc030c1b773","license":"BSD-2-Clause","scripts":{"test":"node test.js && npm run test:types && npm run test:cjs","test:cjs":"node test-cjs.cjs","test:types":"tsc --noEmit"},"version":"1.1.0","_npmUser":{"name":"tadeegan","email":"tadeegan@gmail.com"},"homepage":"https://github.com/tadeegan/locale-currency#readme","keywords":["locale","currency","i18n","internationalization","BCP 47","ISO 4217","ISO 3166-1","country code","minor unit","decimal places","currency exponent","smallest currency unit","stripe"],"repository":{"url":"git+https://github.com/tadeegan/locale-currency.git","type":"git"},"_npmVersion":"11.6.0","description":"A map of locale codes to ISO 4217 currency codes, plus currency decimal-place (minor unit) data. Supports BCP 47, i18n, and ISO 3166-1 alpha-2 formats.","directories":{},"maintainers":[{"name":"tadeegan","email":"tadeegan@gmail.com"}],"sideEffects":false,"_nodeVersion":"24.8.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.2","@types/node":"^24.6.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/locale-currency_1.1.0_1792692554715_0.3356441141844515"}}},"time":{"created":"2016-04-03T22:03:48.156Z","modified":"2026-10-22T18:09:14.983Z","0.0.1":"2016-04-03T22:03:48.156Z","0.0.2":"2017-11-12T18:59:18.688Z","0.0.4":"2025-01-06T22:30:06.038Z","1.0.0":"2025-09-30T19:52:14.836Z","1.0.1":"2026-10-22T03:53:55.034Z","1.1.0":"2026-10-22T18:09:14.809Z"},"bugs":{"url":"https://github.com/tadeegan/locale-currency/issues"},"author":{"name":"Thomas Deegan","email":"tadeegan@gmail.com"},"license":"BSD-2-Clause","homepage":"https://github.com/tadeegan/locale-currency#readme","keywords":["locale","currency","i18n","internationalization","BCP 47","ISO 4217","ISO 3166-1","country code","minor unit","decimal places","currency exponent","smallest currency unit","stripe"],"repository":{"url":"git+https://github.com/tadeegan/locale-currency.git","type":"git"},"description":"A map of locale codes to ISO 4217 currency codes, plus currency decimal-place (minor unit) data. Supports BCP 47, i18n, and ISO 3166-1 alpha-2 formats.","maintainers":[{"name":"tadeegan","email":"tadeegan@gmail.com"}],"readme":"# locale-currency\n\nA map of locale codes to ISO 4217 currency codes, plus currency decimal-place (minor unit) data for converting amounts to their smallest unit. Supports **BCP 47**, **i18n**, and **ISO 3166-1 alpha-2** locale formats.\n\n## Supported Formats\n\n- **BCP 47** language tags (e.g., `zh-Hant-TW`, `en-US`, `pt-BR`)\n- **i18n** locale codes with underscores (e.g., `en_US`, `zh_TW`)\n- **ISO 3166-1 alpha-2** country codes (e.g., `US`, `GB`, `TW`)\n\nThe library intelligently extracts the country/region code from complex locale strings to determine the appropriate currency.\n\n## Installation\n\n```bash\nnpm install locale-currency\n```\n\n## Usage\n\n### ES Modules (recommended)\n\n```javascript\nimport { getCurrency, getLocales } from 'locale-currency';\n\n// Get currency for a locale\ngetCurrency('US');           // 'USD'\ngetCurrency('en-US');        // 'USD'\ngetCurrency('en_US');        // 'USD'\ngetCurrency('zh-Hant-TW');   // 'TWD' - BCP 47 format\ngetCurrency('GB');           // 'GBP'\ngetCurrency('ES');           // 'EUR'\n\n// Get all countries that use a currency\nconst euroCountries = getLocales('EUR');\n// ['AD', 'AT', 'BE', 'CY', 'DE', 'EE', 'ES', 'FI', 'FR', 'GR', ...]\n```\n\n### Currency decimal places\n\nGet the number of decimal places a currency uses and convert amounts to the\nsmallest unit (e.g. cents) for payment APIs such as Stripe.\n\n```javascript\nimport { getExponentForCurrency, convertToSmallestCurrencyUnit } from 'locale-currency';\n\ngetExponentForCurrency('USD');  // 2\ngetExponentForCurrency('JPY');  // 0\ngetExponentForCurrency('KWD');  // 3\n\nconvertToSmallestCurrencyUnit(10.99, 'USD');  // 1099\nconvertToSmallestCurrencyUnit(1000, 'JPY');   // 1000\nconvertToSmallestCurrencyUnit(1.234, 'KWD');  // 1234\n```\n\nThe decimal data is also available as a standalone subpath import, so you can\nuse it without pulling in the locale map:\n\n```javascript\nimport { getExponentForCurrency } from 'locale-currency/decimals';\n```\n\n### CommonJS\n\nThis package is published as ES modules. From CommonJS, use a dynamic `import()`\n(or a plain `require()` on Node 22+, which supports requiring ES modules):\n\n```javascript\nconst { getCurrency, getLocales } = await import('locale-currency');\n\ngetCurrency('en-US'); // 'USD'\n```\n\n## API\n\n### `getCurrency(locale: string): string | null`\n\nReturns the ISO 4217 currency code for a given locale, or `null` if not found.\n\n- **Parameters:**\n  - `locale` - BCP 47, i18n, or ISO 3166-1 alpha-2 code\n- **Returns:** Currency code (e.g., `'USD'`, `'EUR'`) or `null`\n\n### `getLocales(currencyCode: string): string[]`\n\nReturns an array of ISO 3166-1 alpha-2 country codes that use the given currency.\n\n- **Parameters:**\n  - `currencyCode` - ISO 4217 currency code (e.g., `'USD'`, `'EUR'`)\n- **Returns:** Array of country codes\n\n### `getExponentForCurrency(currency: string): number`\n\nReturns the number of decimal places (the ISO 4217 \"minor unit\" exponent) for a currency. Unknown codes fall back to `2`.\n\n- **Parameters:**\n  - `currency` - ISO 4217 currency code (case insensitive)\n- **Returns:** `0`, `1`, `2`, or `3`\n\n### `convertToSmallestCurrencyUnit(amount: number, currency: string): number`\n\nConverts an amount in major units (e.g. dollars) to an integer in the currency's smallest unit (e.g. cents), rounding to the nearest unit.\n\n- **Parameters:**\n  - `amount` - Amount in major units\n  - `currency` - ISO 4217 currency code (case insensitive)\n- **Returns:** Integer amount in the smallest unit\n\n### `currencyDecimalMap: Record<string, number>`\n\nThe underlying map of lowercase ISO 4217 codes to decimal places, exported for direct use.\n\n## Examples\n\n```javascript\nimport { getCurrency, getLocales } from 'locale-currency';\n\n// Case insensitive\ngetCurrency('us');   // 'USD'\ngetCurrency('US');   // 'USD'\ngetCurrency('Us');   // 'USD'\n\n// i18n format with underscores\ngetCurrency('EN_US');  // 'USD'\ngetCurrency('en_us');  // 'USD'\n\n// BCP 47 format with hyphens\ngetCurrency('EN-US');  // 'USD'\ngetCurrency('en-us');  // 'USD'\n\n// Complex BCP 47 with script code\ngetCurrency('zh-Hant-TW');  // 'TWD' (Traditional Chinese in Taiwan)\ngetCurrency('zh-Hans-CN');  // 'CNY' (Simplified Chinese in China)\n\n// Direct country codes\ngetCurrency('GB');  // 'GBP'\ngetCurrency('ES');  // 'EUR'\ngetCurrency('GR');  // 'EUR'\n\n// Find countries using Euro\nconst euroCountries = getLocales('EUR');\nconsole.log(euroCountries.includes('GR'));  // true (Greece)\nconsole.log(euroCountries.includes('FR'));  // true (France)\nconsole.log(euroCountries.includes('ES'));  // true (Spain)\n\n// Combine both: charge a user in their local currency's smallest unit\nconst currency = getCurrency('ja-JP');                     // 'JPY'\nconst amount = convertToSmallestCurrencyUnit(1500, currency); // 1500 (yen has no minor unit)\n```\n","readmeFilename":"README.md"}