@formatjs/utils 1.8.4 → 1.9.1

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.
package/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export { canonicalizeCountryCode } from './src/countryCodes';
2
2
  export { countriesUsingDefaultCurrency, defaultCurrency, } from './src/defaultCurrency';
3
3
  export { defaultLocale } from './src/defaultLocale';
4
4
  export { defaultTimezone } from './src/defaultTimezone';
5
+ export { currencyMinorScale } from './src/iso4217';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultTimezone = exports.defaultLocale = exports.defaultCurrency = exports.countriesUsingDefaultCurrency = exports.canonicalizeCountryCode = void 0;
3
+ exports.currencyMinorScale = exports.defaultTimezone = exports.defaultLocale = exports.defaultCurrency = exports.countriesUsingDefaultCurrency = exports.canonicalizeCountryCode = void 0;
4
4
  var countryCodes_1 = require("./src/countryCodes");
5
5
  Object.defineProperty(exports, "canonicalizeCountryCode", { enumerable: true, get: function () { return countryCodes_1.canonicalizeCountryCode; } });
6
6
  var defaultCurrency_1 = require("./src/defaultCurrency");
@@ -10,3 +10,5 @@ var defaultLocale_1 = require("./src/defaultLocale");
10
10
  Object.defineProperty(exports, "defaultLocale", { enumerable: true, get: function () { return defaultLocale_1.defaultLocale; } });
11
11
  var defaultTimezone_1 = require("./src/defaultTimezone");
12
12
  Object.defineProperty(exports, "defaultTimezone", { enumerable: true, get: function () { return defaultTimezone_1.defaultTimezone; } });
13
+ var iso4217_1 = require("./src/iso4217");
14
+ Object.defineProperty(exports, "currencyMinorScale", { enumerable: true, get: function () { return iso4217_1.currencyMinorScale; } });
package/lib/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export { canonicalizeCountryCode } from './src/countryCodes';
2
2
  export { countriesUsingDefaultCurrency, defaultCurrency, } from './src/defaultCurrency';
3
3
  export { defaultLocale } from './src/defaultLocale';
4
4
  export { defaultTimezone } from './src/defaultTimezone';
5
+ export { currencyMinorScale } from './src/iso4217';
package/lib/index.js CHANGED
@@ -2,3 +2,4 @@ export { canonicalizeCountryCode } from './src/countryCodes';
2
2
  export { countriesUsingDefaultCurrency, defaultCurrency, } from './src/defaultCurrency';
3
3
  export { defaultLocale } from './src/defaultLocale';
4
4
  export { defaultTimezone } from './src/defaultTimezone';
5
+ export { currencyMinorScale } from './src/iso4217';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the number of minor units (decimal places) for a given currency code.
3
+ *
4
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
5
+ * @returns The number of minor units for the specified currency.
6
+ * @throws Will throw an error if the currency code is unknown.
7
+ */
8
+ export declare function currencyMinorUnits(currencyCode: string): number;
@@ -0,0 +1 @@
1
+ { "AFN": 2, "EUR": 2, "ALL": 2, "DZD": 2, "USD": 2, "AOA": 2, "XCD": 2, "ARS": 2, "AMD": 2, "AWG": 2, "AUD": 2, "AZN": 2, "BSD": 2, "BHD": 3, "BDT": 2, "BBD": 2, "BYN": 2, "BZD": 2, "XOF": 0, "BMD": 2, "INR": 2, "BTN": 2, "BOB": 2, "BOV": 2, "BAM": 2, "BWP": 2, "NOK": 2, "BRL": 2, "BND": 2, "BGN": 2, "BIF": 0, "CVE": 2, "KHR": 2, "XAF": 0, "CAD": 2, "KYD": 2, "CLP": 0, "CLF": 4, "CNY": 2, "COP": 2, "COU": 2, "KMF": 0, "CDF": 2, "NZD": 2, "CRC": 2, "CUP": 2, "ANG": 2, "CZK": 2, "DKK": 2, "DJF": 0, "DOP": 2, "EGP": 2, "SVC": 2, "ERN": 2, "SZL": 2, "ETB": 2, "FKP": 2, "FJD": 2, "XPF": 0, "GMD": 2, "GEL": 2, "GHS": 2, "GIP": 2, "GTQ": 2, "GBP": 2, "GNF": 0, "GYD": 2, "HTG": 2, "HNL": 2, "HKD": 2, "HUF": 2, "ISK": 0, "IDR": 2, "IRR": 2, "IQD": 3, "ILS": 2, "JMD": 2, "JPY": 0, "JOD": 3, "KZT": 2, "KES": 2, "KPW": 2, "KRW": 0, "KWD": 3, "KGS": 2, "LAK": 2, "LBP": 2, "LSL": 2, "ZAR": 2, "LRD": 2, "LYD": 3, "CHF": 2, "MOP": 2, "MKD": 2, "MGA": 2, "MWK": 2, "MYR": 2, "MVR": 2, "MRU": 2, "MUR": 2, "MXN": 2, "MXV": 2, "MDL": 2, "MNT": 2, "MAD": 2, "MZN": 2, "MMK": 2, "NAD": 2, "NPR": 2, "NIO": 2, "NGN": 2, "OMR": 3, "PKR": 2, "PAB": 2, "PGK": 2, "PYG": 0, "PEN": 2, "PHP": 2, "PLN": 2, "QAR": 2, "RON": 2, "RUB": 2, "RWF": 0, "SHP": 2, "WST": 2, "STN": 2, "SAR": 2, "RSD": 2, "SCR": 2, "SLE": 2, "SGD": 2, "SBD": 2, "SOS": 2, "SSP": 2, "LKR": 2, "SDG": 2, "SRD": 2, "SEK": 2, "CHE": 2, "CHW": 2, "SYP": 2, "TWD": 2, "TJS": 2, "TZS": 2, "THB": 2, "TOP": 2, "TTD": 2, "TND": 3, "TRY": 2, "TMT": 2, "UGX": 0, "UAH": 2, "AED": 2, "USN": 2, "UYU": 2, "UYI": 0, "UYW": 4, "UZS": 2, "VUV": 0, "VES": 2, "VED": 2, "VND": 0, "YER": 2, "ZMW": 2, "ZWG": 2 }
@@ -0,0 +1,15 @@
1
+ import * as iso4217 from './currencyMinorUnits.generated.json';
2
+ /**
3
+ * Returns the number of minor units (decimal places) for a given currency code.
4
+ *
5
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
6
+ * @returns The number of minor units for the specified currency.
7
+ * @throws Will throw an error if the currency code is unknown.
8
+ */
9
+ export function currencyMinorUnits(currencyCode) {
10
+ var minorUnits = iso4217[currencyCode.toUpperCase()];
11
+ if (minorUnits == null) {
12
+ throw new Error("Unknown currency code: ".concat(currencyCode));
13
+ }
14
+ return minorUnits;
15
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns the minor unit scale for a given currency code.
3
+ *
4
+ * The minor unit scale is the number of decimal places used for the currency.
5
+ * For example, USD has 2 decimal places, so the minor unit scale is 100.
6
+ *
7
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
8
+ * @returns The minor unit scale as a power of 10.
9
+ */
10
+ export declare function currencyMinorScale(currencyCode: string): number;
@@ -0,0 +1,27 @@
1
+ import * as iso4217 from './currencyMinorUnits.generated.json';
2
+ /**
3
+ * Returns the number of minor units (decimal places) for a given currency code.
4
+ *
5
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
6
+ * @returns The number of minor units for the specified currency.
7
+ * @throws Will throw an error if the currency code is unknown.
8
+ */
9
+ function currencyMinorUnits(currencyCode) {
10
+ var minorUnits = iso4217[currencyCode.toUpperCase()];
11
+ if (minorUnits == null) {
12
+ throw new Error("Unknown currency code: ".concat(currencyCode));
13
+ }
14
+ return minorUnits;
15
+ }
16
+ /**
17
+ * Returns the minor unit scale for a given currency code.
18
+ *
19
+ * The minor unit scale is the number of decimal places used for the currency.
20
+ * For example, USD has 2 decimal places, so the minor unit scale is 100.
21
+ *
22
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
23
+ * @returns The minor unit scale as a power of 10.
24
+ */
25
+ export function currencyMinorScale(currencyCode) {
26
+ return Math.pow(10, currencyMinorUnits(currencyCode));
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/utils",
3
- "version": "1.8.4",
3
+ "version": "1.9.1",
4
4
  "description": "Collection of useful intl utilities",
5
5
  "main": "index.js",
6
6
  "module": "lib/index.js",
@@ -23,5 +23,8 @@
23
23
  "dependencies": {
24
24
  "tslib": "2",
25
25
  "@formatjs/fast-memoize": "2.2.6"
26
+ },
27
+ "devDependencies": {
28
+ "fast-xml-parser": "^4.5.1"
26
29
  }
27
30
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the number of minor units (decimal places) for a given currency code.
3
+ *
4
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
5
+ * @returns The number of minor units for the specified currency.
6
+ * @throws Will throw an error if the currency code is unknown.
7
+ */
8
+ export declare function currencyMinorUnits(currencyCode: string): number;
@@ -0,0 +1 @@
1
+ {"AFN":2,"EUR":2,"ALL":2,"DZD":2,"USD":2,"AOA":2,"XCD":2,"ARS":2,"AMD":2,"AWG":2,"AUD":2,"AZN":2,"BSD":2,"BHD":3,"BDT":2,"BBD":2,"BYN":2,"BZD":2,"XOF":0,"BMD":2,"INR":2,"BTN":2,"BOB":2,"BOV":2,"BAM":2,"BWP":2,"NOK":2,"BRL":2,"BND":2,"BGN":2,"BIF":0,"CVE":2,"KHR":2,"XAF":0,"CAD":2,"KYD":2,"CLP":0,"CLF":4,"CNY":2,"COP":2,"COU":2,"KMF":0,"CDF":2,"NZD":2,"CRC":2,"CUP":2,"ANG":2,"CZK":2,"DKK":2,"DJF":0,"DOP":2,"EGP":2,"SVC":2,"ERN":2,"SZL":2,"ETB":2,"FKP":2,"FJD":2,"XPF":0,"GMD":2,"GEL":2,"GHS":2,"GIP":2,"GTQ":2,"GBP":2,"GNF":0,"GYD":2,"HTG":2,"HNL":2,"HKD":2,"HUF":2,"ISK":0,"IDR":2,"IRR":2,"IQD":3,"ILS":2,"JMD":2,"JPY":0,"JOD":3,"KZT":2,"KES":2,"KPW":2,"KRW":0,"KWD":3,"KGS":2,"LAK":2,"LBP":2,"LSL":2,"ZAR":2,"LRD":2,"LYD":3,"CHF":2,"MOP":2,"MKD":2,"MGA":2,"MWK":2,"MYR":2,"MVR":2,"MRU":2,"MUR":2,"MXN":2,"MXV":2,"MDL":2,"MNT":2,"MAD":2,"MZN":2,"MMK":2,"NAD":2,"NPR":2,"NIO":2,"NGN":2,"OMR":3,"PKR":2,"PAB":2,"PGK":2,"PYG":0,"PEN":2,"PHP":2,"PLN":2,"QAR":2,"RON":2,"RUB":2,"RWF":0,"SHP":2,"WST":2,"STN":2,"SAR":2,"RSD":2,"SCR":2,"SLE":2,"SGD":2,"SBD":2,"SOS":2,"SSP":2,"LKR":2,"SDG":2,"SRD":2,"SEK":2,"CHE":2,"CHW":2,"SYP":2,"TWD":2,"TJS":2,"TZS":2,"THB":2,"TOP":2,"TTD":2,"TND":3,"TRY":2,"TMT":2,"UGX":0,"UAH":2,"AED":2,"USN":2,"UYU":2,"UYI":0,"UYW":4,"UZS":2,"VUV":0,"VES":2,"VED":2,"VND":0,"YER":2,"ZMW":2,"ZWG":2}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.currencyMinorUnits = currencyMinorUnits;
4
+ var tslib_1 = require("tslib");
5
+ var iso4217 = tslib_1.__importStar(require("./currencyMinorUnits.generated.json"));
6
+ /**
7
+ * Returns the number of minor units (decimal places) for a given currency code.
8
+ *
9
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
10
+ * @returns The number of minor units for the specified currency.
11
+ * @throws Will throw an error if the currency code is unknown.
12
+ */
13
+ function currencyMinorUnits(currencyCode) {
14
+ var minorUnits = iso4217[currencyCode.toUpperCase()];
15
+ if (minorUnits == null) {
16
+ throw new Error("Unknown currency code: ".concat(currencyCode));
17
+ }
18
+ return minorUnits;
19
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns the minor unit scale for a given currency code.
3
+ *
4
+ * The minor unit scale is the number of decimal places used for the currency.
5
+ * For example, USD has 2 decimal places, so the minor unit scale is 100.
6
+ *
7
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
8
+ * @returns The minor unit scale as a power of 10.
9
+ */
10
+ export declare function currencyMinorScale(currencyCode: string): number;
package/src/iso4217.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.currencyMinorScale = currencyMinorScale;
4
+ var tslib_1 = require("tslib");
5
+ var iso4217 = tslib_1.__importStar(require("./currencyMinorUnits.generated.json"));
6
+ /**
7
+ * Returns the number of minor units (decimal places) for a given currency code.
8
+ *
9
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
10
+ * @returns The number of minor units for the specified currency.
11
+ * @throws Will throw an error if the currency code is unknown.
12
+ */
13
+ function currencyMinorUnits(currencyCode) {
14
+ var minorUnits = iso4217[currencyCode.toUpperCase()];
15
+ if (minorUnits == null) {
16
+ throw new Error("Unknown currency code: ".concat(currencyCode));
17
+ }
18
+ return minorUnits;
19
+ }
20
+ /**
21
+ * Returns the minor unit scale for a given currency code.
22
+ *
23
+ * The minor unit scale is the number of decimal places used for the currency.
24
+ * For example, USD has 2 decimal places, so the minor unit scale is 100.
25
+ *
26
+ * @param currencyCode - The ISO 4217 currency code (e.g., 'USD', 'EUR').
27
+ * @returns The minor unit scale as a power of 10.
28
+ */
29
+ function currencyMinorScale(currencyCode) {
30
+ return Math.pow(10, currencyMinorUnits(currencyCode));
31
+ }