@formatjs/utils 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,3 +4,9 @@
4
4
  * @returns default currency code, or USD if not found
5
5
  */
6
6
  export declare function defaultCurrency(countryCode?: string): string | undefined;
7
+ /**
8
+ * Look up countries using a default currency.
9
+ * @param currencyCode currency code (ISO 4217)
10
+ * @returns list of country codes (alpha-2)
11
+ */
12
+ export declare function countriesUsingDefaultCurrency(currencyCode?: string): string[];
@@ -1,5 +1,13 @@
1
1
  import { canonicalizeCountryCode } from './countryCodes';
2
2
  import * as data from './defaultCurrencyData.generated.json';
3
+ var COUNTRIES_BY_DEFAULT_CURRENCY = Object.keys(data).reduce(function (acc, countryCode) {
4
+ var currencyCode = data[countryCode];
5
+ if (!acc[currencyCode]) {
6
+ acc[currencyCode] = [];
7
+ }
8
+ acc[currencyCode].push(countryCode);
9
+ return acc;
10
+ }, {});
3
11
  /**
4
12
  * Look up default currency for a country code.
5
13
  * @param countryCode country code (alpha-2)
@@ -9,3 +17,11 @@ export function defaultCurrency(countryCode) {
9
17
  countryCode = canonicalizeCountryCode(countryCode);
10
18
  return ((countryCode && countryCode in data && data[countryCode]) || 'USD');
11
19
  }
20
+ /**
21
+ * Look up countries using a default currency.
22
+ * @param currencyCode currency code (ISO 4217)
23
+ * @returns list of country codes (alpha-2)
24
+ */
25
+ export function countriesUsingDefaultCurrency(currencyCode) {
26
+ return COUNTRIES_BY_DEFAULT_CURRENCY[currencyCode || 'USD'] || [];
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/utils",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Collection of useful intl utilities",
5
5
  "main": "index.js",
6
6
  "module": "lib/index.js",
@@ -4,3 +4,9 @@
4
4
  * @returns default currency code, or USD if not found
5
5
  */
6
6
  export declare function defaultCurrency(countryCode?: string): string | undefined;
7
+ /**
8
+ * Look up countries using a default currency.
9
+ * @param currencyCode currency code (ISO 4217)
10
+ * @returns list of country codes (alpha-2)
11
+ */
12
+ export declare function countriesUsingDefaultCurrency(currencyCode?: string): string[];
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultCurrency = defaultCurrency;
4
+ exports.countriesUsingDefaultCurrency = countriesUsingDefaultCurrency;
4
5
  var tslib_1 = require("tslib");
5
6
  var countryCodes_1 = require("./countryCodes");
6
7
  var data = tslib_1.__importStar(require("./defaultCurrencyData.generated.json"));
8
+ var COUNTRIES_BY_DEFAULT_CURRENCY = Object.keys(data).reduce(function (acc, countryCode) {
9
+ var currencyCode = data[countryCode];
10
+ if (!acc[currencyCode]) {
11
+ acc[currencyCode] = [];
12
+ }
13
+ acc[currencyCode].push(countryCode);
14
+ return acc;
15
+ }, {});
7
16
  /**
8
17
  * Look up default currency for a country code.
9
18
  * @param countryCode country code (alpha-2)
@@ -13,3 +22,11 @@ function defaultCurrency(countryCode) {
13
22
  countryCode = (0, countryCodes_1.canonicalizeCountryCode)(countryCode);
14
23
  return ((countryCode && countryCode in data && data[countryCode]) || 'USD');
15
24
  }
25
+ /**
26
+ * Look up countries using a default currency.
27
+ * @param currencyCode currency code (ISO 4217)
28
+ * @returns list of country codes (alpha-2)
29
+ */
30
+ function countriesUsingDefaultCurrency(currencyCode) {
31
+ return COUNTRIES_BY_DEFAULT_CURRENCY[currencyCode || 'USD'] || [];
32
+ }