From 89e7ca9d7a16c864ce86961c24801a1a5b1b55f1 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Tue, 11 Jun 2024 10:25:07 +0530 Subject: [PATCH] [fix]: fix i18nify currency inconsistency [ATLAS-204] (#154) * [chore]: add logic to replace INTL currency symbol with the one in i18nify-data * [chore]: add updated i18nify data * [chore]: modify INTL_MAPPING to use i18nify-data * Create poor-moose-drum.md * [chore]: minor changes * [fix]: fix type error * [chore]: update localised currency symbol for other currency codes * [fix]: fix i18nify-data currency inconsistency * [test]: add missing UTs * [chore]: resolve review comments * [chore]: resolve review comments * [chore]: resolve review comments * [chore]: resolve review comments * [chore]: resolve review comments --- .changeset/poor-moose-drum.md | 5 + i18nify-data/currency/data.json | 692 +++--------------- .../i18nify-go/modules/currency/data.json | 692 +++--------------- .../currency/__tests__/formatNumber.test.ts | 59 ++ .../__tests__/formatNumberByParts.test.ts | 72 ++ .../__tests__/mocks/formatNumberToParts.ts | 548 ++++++++++++++ .../__tests__/mocks/transformPartsFromIntl.ts | 8 + .../__tests__/transformPartsFromIntl.test.ts | 46 ++ .../src/modules/currency/constants.ts | 41 ++ .../modules/currency/data/currencyConfig.json | 78 +- .../src/modules/currency/formatNumber.ts | 20 +- .../modules/currency/formatNumberByParts.ts | 12 +- .../i18nify-js/src/modules/currency/types.ts | 1 + .../i18nify-js/src/modules/currency/utils.ts | 35 + 14 files changed, 1116 insertions(+), 1193 deletions(-) create mode 100644 .changeset/poor-moose-drum.md create mode 100644 packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts create mode 100644 packages/i18nify-js/src/modules/currency/__tests__/mocks/transformPartsFromIntl.ts create mode 100644 packages/i18nify-js/src/modules/currency/__tests__/transformPartsFromIntl.test.ts create mode 100644 packages/i18nify-js/src/modules/currency/utils.ts diff --git a/.changeset/poor-moose-drum.md b/.changeset/poor-moose-drum.md new file mode 100644 index 00000000..257f0778 --- /dev/null +++ b/.changeset/poor-moose-drum.md @@ -0,0 +1,5 @@ +--- +"@razorpay/i18nify-js": patch +--- + +[fix]: fix i18nify currency inconsistency diff --git a/i18nify-data/currency/data.json b/i18nify-data/currency/data.json index 625705b4..9c50340c 100644 --- a/i18nify-data/currency/data.json +++ b/i18nify-data/currency/data.json @@ -74,14 +74,7 @@ "numeric_code": "840", "minor_unit": "2", "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "AOA": { "name": "Kwanza", @@ -105,7 +98,7 @@ "name": "East Caribbean Dollar", "numeric_code": "951", "minor_unit": "2", - "symbol": "$", + "symbol": "EC$", "physical_currency_denominations": [ "1", "2", @@ -120,7 +113,7 @@ "name": "Argentine Peso", "numeric_code": "32", "minor_unit": "2", - "symbol": "$", + "symbol": "ARS", "physical_currency_denominations": [ "1", "2", @@ -156,7 +149,7 @@ "name": "Aruban Florin", "numeric_code": "533", "minor_unit": "2", - "symbol": "ƒ", + "symbol": "Aƒ", "physical_currency_denominations": [ "5", "10", @@ -174,42 +167,22 @@ "name": "Australian Dollar", "numeric_code": "36", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "A$", + "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "AZN": { "name": "Azerbaijan Manat", "numeric_code": "944", "minor_unit": "2", "symbol": "₼", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "BSD": { "name": "Bahamian Dollar", "numeric_code": "44", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "symbol": "BSD", + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "BHD": { "name": "Bahraini Dinar", @@ -248,27 +221,15 @@ "name": "Barbados Dollar", "numeric_code": "52", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25" - ] + "symbol": "Bds$", + "physical_currency_denominations": ["1", "5", "10", "25"] }, "BYN": { "name": "Belarusian Ruble", "numeric_code": "933", "minor_unit": "2", - "symbol": "Br", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "Rbl", + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "BZD": { "name": "Belize Dollar", @@ -312,15 +273,8 @@ "name": "Bermudian Dollar", "numeric_code": "60", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "BD$", + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "INR": { "name": "Indian Rupee", @@ -361,40 +315,21 @@ "numeric_code": "68", "minor_unit": "2", "symbol": "Bs.", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "BOV": { "name": "Mvdol", "numeric_code": "984", "minor_unit": "2", - "symbol": "nan", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "symbol": "Bs", + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "BAM": { "name": "Convertible Mark", "numeric_code": "977", "minor_unit": "2", "symbol": "KM", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "BWP": { "name": "Pula", @@ -499,7 +434,7 @@ "name": "Cabo Verde Escudo", "numeric_code": "132", "minor_unit": "2", - "symbol": "$", + "symbol": "CVE", "physical_currency_denominations": [ "200", "500", @@ -530,7 +465,7 @@ "name": "CFA Franc BEAC", "numeric_code": "950", "minor_unit": "0", - "symbol": "CFA", + "symbol": "FCFA", "physical_currency_denominations": [ "500", "1000", @@ -546,34 +481,21 @@ "name": "Canadian Dollar", "numeric_code": "124", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "CA$", + "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "KYD": { "name": "Cayman Islands Dollar", "numeric_code": "136", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "symbol": "CI$", + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "CLP": { "name": "Chilean Peso", "numeric_code": "152", "minor_unit": "0", - "symbol": "$", + "symbol": "CLP", "physical_currency_denominations": [ "1", "5", @@ -591,15 +513,13 @@ "numeric_code": "990", "minor_unit": "4", "symbol": "UF", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "CNY": { "name": "Yuan Renminbi", "numeric_code": "156", "minor_unit": "2", - "symbol": "¥", + "symbol": "CN¥", "physical_currency_denominations": [ "1", "2", @@ -614,7 +534,7 @@ "name": "Colombian Peso", "numeric_code": "170", "minor_unit": "2", - "symbol": "$", + "symbol": "COL$", "physical_currency_denominations": [ "1000", "2000", @@ -629,9 +549,7 @@ "numeric_code": "970", "minor_unit": "2", "symbol": "UVR", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "KMF": { "name": "Comorian Franc", @@ -671,14 +589,8 @@ "name": "New Zealand Dollar", "numeric_code": "554", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20" - ] + "symbol": "NZ$", + "physical_currency_denominations": ["1", "2", "5", "10", "20"] }, "CRC": { "name": "Costa Rican Colon", @@ -719,15 +631,8 @@ "name": "Cuban Peso", "numeric_code": "192", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "3", - "5", - "10", - "20", - "50" - ] + "symbol": "$MN", + "physical_currency_denominations": ["1", "3", "5", "10", "20", "50"] }, "CUC": { "name": "Peso Convertible", @@ -789,56 +694,34 @@ "numeric_code": "208", "minor_unit": "2", "symbol": "kr", - "physical_currency_denominations": [ - "50", - "100", - "200", - "500", - "1000" - ] + "physical_currency_denominations": ["50", "100", "200", "500", "1000"] }, "DJF": { "name": "Djibouti Franc", "numeric_code": "262", "minor_unit": "0", "symbol": "Fdj", - "physical_currency_denominations": [ - "1000", - "2000", - "5000", - "10000" - ] + "physical_currency_denominations": ["1000", "2000", "5000", "10000"] }, "DOP": { "name": "Dominican Peso", "numeric_code": "214", "minor_unit": "2", "symbol": "RD$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50"] }, "EGP": { "name": "Egyptian Pound", "numeric_code": "818", "minor_unit": "2", - "symbol": "£", - "physical_currency_denominations": [ - "25", - "50", - "100", - "200" - ] + "symbol": "E£", + "physical_currency_denominations": ["25", "50", "100", "200"] }, "SVC": { "name": "El Salvador Colon", "numeric_code": "222", "minor_unit": "2", - "symbol": "$", + "symbol": "₡", "physical_currency_denominations": [ "0.01", "0.05", @@ -858,89 +741,49 @@ "numeric_code": "232", "minor_unit": "2", "symbol": "Nfk", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "SZL": { "name": "Lilangeni", "numeric_code": "748", "minor_unit": "2", "symbol": "E", - "physical_currency_denominations": [ - "2" - ] + "physical_currency_denominations": ["2"] }, "ETB": { "name": "Ethiopian Birr", "numeric_code": "230", "minor_unit": "2", "symbol": "Br", - "physical_currency_denominations": [ - "1", - "5", - "10", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "50", "100"] }, "FKP": { "name": "Falkland Islands Pound", "numeric_code": "238", "minor_unit": "2", - "symbol": "£", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20", - "50" - ] + "symbol": "FK£", + "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "FJD": { "name": "Fiji Dollar", "numeric_code": "242", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "2", - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "FJ$", + "physical_currency_denominations": ["2", "5", "10", "20", "50", "100"] }, "XPF": { "name": "CFP Franc", "numeric_code": "953", "minor_unit": "0", "symbol": "F", - "physical_currency_denominations": [ - "500", - "1000", - "2000", - "5000" - ] + "physical_currency_denominations": ["500", "1000", "2000", "5000"] }, "GMD": { "name": "Dalasi", "numeric_code": "270", "minor_unit": "2", "symbol": "D", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "GEL": { "name": "Lari", @@ -963,56 +806,28 @@ "numeric_code": "936", "minor_unit": "2", "symbol": "GH₵", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "GIP": { "name": "Gibraltar Pound", "numeric_code": "292", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["5", "10", "20", "50", "100", "200"] }, "GTQ": { "name": "Quetzal", "numeric_code": "320", "minor_unit": "2", "symbol": "Q", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "GBP": { "name": "Pound Sterling", "numeric_code": "826", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "GNF": { "name": "Guinean Franc", @@ -1034,7 +849,7 @@ "name": "Guyana Dollar", "numeric_code": "328", "minor_unit": "2", - "symbol": "$", + "symbol": "GY$", "physical_currency_denominations": [ "20", "100", @@ -1081,7 +896,7 @@ "name": "Hong Kong Dollar", "numeric_code": "344", "minor_unit": "2", - "symbol": "$", + "symbol": "HK$", "physical_currency_denominations": [ "10", "20", @@ -1182,50 +997,28 @@ "numeric_code": "376", "minor_unit": "2", "symbol": "₪", - "physical_currency_denominations": [ - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["20", "50", "100", "200"] }, "JMD": { "name": "Jamaican Dollar", "numeric_code": "388", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "50", - "100", - "500", - "1000", - "5000" - ] + "symbol": "J$", + "physical_currency_denominations": ["50", "100", "500", "1000", "5000"] }, "JPY": { "name": "Yen", "numeric_code": "392", "minor_unit": "0", "symbol": "¥", - "physical_currency_denominations": [ - "1000", - "2000", - "5000", - "10000" - ] + "physical_currency_denominations": ["1000", "2000", "5000", "10000"] }, "JOD": { "name": "Jordanian Dinar", "numeric_code": "400", "minor_unit": "3", "symbol": "JD", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "KZT": { "name": "Tenge", @@ -1249,25 +1042,14 @@ "numeric_code": "404", "minor_unit": "2", "symbol": "KSh", - "physical_currency_denominations": [ - "50", - "100", - "200", - "500", - "1000" - ] + "physical_currency_denominations": ["50", "100", "200", "500", "1000"] }, "KPW": { "name": "North Korean Won", "numeric_code": "408", "minor_unit": "2", "symbol": "₩", - "physical_currency_denominations": [ - "5", - "10", - "50", - "100" - ] + "physical_currency_denominations": ["5", "10", "50", "100"] }, "KRW": { "name": "Won", @@ -1287,14 +1069,7 @@ "numeric_code": "414", "minor_unit": "3", "symbol": "د.ك", - "physical_currency_denominations": [ - "0.25", - "0.5", - "1", - "5", - "10", - "20" - ] + "physical_currency_denominations": ["0.25", "0.5", "1", "5", "10", "20"] }, "KGS": { "name": "Som", @@ -1332,18 +1107,14 @@ "name": "Lebanese Pound", "numeric_code": "422", "minor_unit": "2", - "symbol": "£", - "physical_currency_denominations": [ - "25000", - "50000", - "100000" - ] + "symbol": "L£", + "physical_currency_denominations": ["25000", "50000", "100000"] }, "LSL": { "name": "Loti", "numeric_code": "426", "minor_unit": "2", - "symbol": "L", + "symbol": "M", "physical_currency_denominations": [ "1", "2", @@ -1361,40 +1132,21 @@ "numeric_code": "710", "minor_unit": "2", "symbol": "R", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "LRD": { "name": "Liberian Dollar", "numeric_code": "430", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100", - "500" - ] + "symbol": "L$", + "physical_currency_denominations": ["5", "10", "20", "50", "100", "500"] }, "LYD": { "name": "Libyan Dinar", "numeric_code": "434", "minor_unit": "3", "symbol": "LD", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "CHF": { "name": "Swiss Franc", @@ -1414,14 +1166,8 @@ "name": "Pataca", "numeric_code": "446", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "500" - ] + "symbol": "MOP$", + "physical_currency_denominations": ["10", "20", "50", "100", "500"] }, "MKD": { "name": "Denar", @@ -1480,14 +1226,7 @@ "numeric_code": "458", "minor_unit": "2", "symbol": "RM", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "MVR": { "name": "Rufiyaa", @@ -1541,23 +1280,15 @@ "name": "Mexican Peso", "numeric_code": "484", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "20", - "50", - "100", - "200", - "500" - ] + "symbol": "Mex$", + "physical_currency_denominations": ["20", "50", "100", "200", "500"] }, "MXV": { "name": "Mexican Unidad de Inversion (UDI)", "numeric_code": "979", "minor_unit": "2", - "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "symbol": "UDI", + "physical_currency_denominations": ["nan"] }, "MDL": { "name": "Moldovan Leu", @@ -1600,12 +1331,7 @@ "numeric_code": "504", "minor_unit": "2", "symbol": "DH", - "physical_currency_denominations": [ - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["20", "50", "100", "200"] }, "MZN": { "name": "Mozambique Metical", @@ -1640,14 +1366,8 @@ "name": "Namibia Dollar", "numeric_code": "516", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "symbol": "N$", + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "NPR": { "name": "Nepalese Rupee", @@ -1702,13 +1422,7 @@ "numeric_code": "512", "minor_unit": "3", "symbol": "ر.ع.", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "PKR": { "name": "Pakistan Rupee", @@ -1729,28 +1443,14 @@ "numeric_code": "590", "minor_unit": "2", "symbol": "B/.", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "PGK": { "name": "Kina", "numeric_code": "598", "minor_unit": "2", "symbol": "K", - "physical_currency_denominations": [ - "2", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["2", "5", "10", "20", "50", "100"] }, "PYG": { "name": "Guarani", @@ -1771,13 +1471,7 @@ "numeric_code": "604", "minor_unit": "2", "symbol": "S/", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "PHP": { "name": "Philippine Peso", @@ -1798,40 +1492,21 @@ "numeric_code": "985", "minor_unit": "2", "symbol": "zł", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "QAR": { "name": "Qatari Rial", "numeric_code": "634", "minor_unit": "2", "symbol": "ر.ق", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50"] }, "RON": { "name": "Romanian Leu", "numeric_code": "946", "minor_unit": "2", "symbol": "lei", - "physical_currency_denominations": [ - "1", - "5", - "10", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["1", "5", "10", "50", "100", "200"] }, "RUB": { "name": "Russian Ruble", @@ -1853,62 +1528,35 @@ "numeric_code": "646", "minor_unit": "0", "symbol": "FRw", - "physical_currency_denominations": [ - "500", - "1000", - "2000", - "5000" - ] + "physical_currency_denominations": ["500", "1000", "2000", "5000"] }, "SHP": { "name": "Saint Helena Pound", "numeric_code": "654", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["5", "10", "20", "50"] }, "WST": { "name": "Tala", "numeric_code": "882", "minor_unit": "2", - "symbol": "T", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100" - ] + "symbol": "WS$", + "physical_currency_denominations": ["10", "20", "50", "100"] }, "STN": { "name": "Dobra", "numeric_code": "930", "minor_unit": "2", "symbol": "Db", - "physical_currency_denominations": [ - "100", - "200", - "500", - "1000" - ] + "physical_currency_denominations": ["100", "200", "500", "1000"] }, "SAR": { "name": "Saudi Riyal", "numeric_code": "682", "minor_unit": "2", "symbol": "ر.س", - "physical_currency_denominations": [ - "1", - "5", - "10", - "50", - "100", - "500" - ] + "physical_currency_denominations": ["1", "5", "10", "50", "100", "500"] }, "RSD": { "name": "Serbian Dinar", @@ -1931,13 +1579,7 @@ "numeric_code": "690", "minor_unit": "2", "symbol": "₨", - "physical_currency_denominations": [ - "10", - "25", - "50", - "100", - "500" - ] + "physical_currency_denominations": ["10", "25", "50", "100", "500"] }, "SLL": { "name": "Leone", @@ -1959,53 +1601,28 @@ "numeric_code": "702", "minor_unit": "2", "symbol": "S$", - "physical_currency_denominations": [ - "2", - "5", - "10", - "50", - "100", - "1000" - ] + "physical_currency_denominations": ["2", "5", "10", "50", "100", "1000"] }, "SBD": { "name": "Solomon Islands Dollar", "numeric_code": "90", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "SI$", + "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "SOS": { "name": "Somali Shilling", "numeric_code": "706", "minor_unit": "2", "symbol": "S", - "physical_currency_denominations": [ - "500", - "1000", - "5000", - "10000" - ] + "physical_currency_denominations": ["500", "1000", "5000", "10000"] }, "SSP": { "name": "South Sudanese Pound", "numeric_code": "728", "minor_unit": "2", - "symbol": "£", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "symbol": "SS£", + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "LKR": { "name": "Sri Lanka Rupee", @@ -2043,14 +1660,8 @@ "name": "Surinam Dollar", "numeric_code": "968", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "SRD", + "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "SEK": { "name": "Swedish Krona", @@ -2072,44 +1683,28 @@ "numeric_code": "947", "minor_unit": "2", "symbol": "CHE", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "CHW": { "name": "WIR Franc", "numeric_code": "948", "minor_unit": "2", "symbol": "CHW", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "SYP": { "name": "Syrian Pound", "numeric_code": "760", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "50", - "100", - "200", - "500", - "1000" - ] + "physical_currency_denominations": ["50", "100", "200", "500", "1000"] }, "TWD": { "name": "New Taiwan Dollar", "numeric_code": "901", "minor_unit": "2", "symbol": "NT$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "TJS": { "name": "Somoni", @@ -2144,53 +1739,28 @@ "numeric_code": "764", "minor_unit": "2", "symbol": "฿", - "physical_currency_denominations": [ - "20", - "50", - "100", - "500", - "1000" - ] + "physical_currency_denominations": ["20", "50", "100", "500", "1000"] }, "TOP": { "name": "Pa’anga", "numeric_code": "776", "minor_unit": "2", "symbol": "T$", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "TTD": { "name": "Trinidad and Tobago Dollar", "numeric_code": "780", "minor_unit": "2", "symbol": "TT$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "TND": { "name": "Tunisian Dinar", "numeric_code": "788", "minor_unit": "3", "symbol": "DT", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["5", "10", "20", "50"] }, "TRY": { "name": "Turkish Lira", @@ -2273,10 +1843,8 @@ "name": "Uruguay Peso en Unidades Indexadas (URUIURUI)", "numeric_code": "858", "minor_unit": "2", - "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "symbol": "$U", + "physical_currency_denominations": ["nan"] }, "UYU": { "name": "Peso Uruguayo", @@ -2298,10 +1866,8 @@ "name": "Unidad Previsional", "numeric_code": "927", "minor_unit": "4", - "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "symbol": "UR", + "physical_currency_denominations": ["nan"] }, "UZS": { "name": "Uzbekistan Sum", @@ -2338,28 +1904,14 @@ "numeric_code": "928", "minor_unit": "2", "symbol": "Bs.S.", - "physical_currency_denominations": [ - "2", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["2", "5", "10", "20", "50", "100"] }, "VED": { "name": "Bolívar Soberano", "numeric_code": "926", "minor_unit": "2", "symbol": "Bs.S.", - "physical_currency_denominations": [ - "2", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["2", "5", "10", "20", "50", "100"] }, "VND": { "name": "Dong", @@ -2383,13 +1935,7 @@ "numeric_code": "886", "minor_unit": "2", "symbol": "﷼", - "physical_currency_denominations": [ - "200", - "500", - "1000", - "2000", - "5000" - ] + "physical_currency_denominations": ["200", "500", "1000", "2000", "5000"] }, "ZMW": { "name": "Zambian Kwacha", @@ -2410,7 +1956,7 @@ "name": "Zimbabwe Dollar", "numeric_code": "932", "minor_unit": "2", - "symbol": "$", + "symbol": "Z$", "physical_currency_denominations": [ "1", "5", @@ -2424,4 +1970,4 @@ ] } } -} \ No newline at end of file +} diff --git a/packages/i18nify-go/modules/currency/data.json b/packages/i18nify-go/modules/currency/data.json index 625705b4..9c50340c 100644 --- a/packages/i18nify-go/modules/currency/data.json +++ b/packages/i18nify-go/modules/currency/data.json @@ -74,14 +74,7 @@ "numeric_code": "840", "minor_unit": "2", "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "AOA": { "name": "Kwanza", @@ -105,7 +98,7 @@ "name": "East Caribbean Dollar", "numeric_code": "951", "minor_unit": "2", - "symbol": "$", + "symbol": "EC$", "physical_currency_denominations": [ "1", "2", @@ -120,7 +113,7 @@ "name": "Argentine Peso", "numeric_code": "32", "minor_unit": "2", - "symbol": "$", + "symbol": "ARS", "physical_currency_denominations": [ "1", "2", @@ -156,7 +149,7 @@ "name": "Aruban Florin", "numeric_code": "533", "minor_unit": "2", - "symbol": "ƒ", + "symbol": "Aƒ", "physical_currency_denominations": [ "5", "10", @@ -174,42 +167,22 @@ "name": "Australian Dollar", "numeric_code": "36", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "A$", + "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "AZN": { "name": "Azerbaijan Manat", "numeric_code": "944", "minor_unit": "2", "symbol": "₼", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "BSD": { "name": "Bahamian Dollar", "numeric_code": "44", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "symbol": "BSD", + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "BHD": { "name": "Bahraini Dinar", @@ -248,27 +221,15 @@ "name": "Barbados Dollar", "numeric_code": "52", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25" - ] + "symbol": "Bds$", + "physical_currency_denominations": ["1", "5", "10", "25"] }, "BYN": { "name": "Belarusian Ruble", "numeric_code": "933", "minor_unit": "2", - "symbol": "Br", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "Rbl", + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "BZD": { "name": "Belize Dollar", @@ -312,15 +273,8 @@ "name": "Bermudian Dollar", "numeric_code": "60", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "BD$", + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "INR": { "name": "Indian Rupee", @@ -361,40 +315,21 @@ "numeric_code": "68", "minor_unit": "2", "symbol": "Bs.", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "BOV": { "name": "Mvdol", "numeric_code": "984", "minor_unit": "2", - "symbol": "nan", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "symbol": "Bs", + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "BAM": { "name": "Convertible Mark", "numeric_code": "977", "minor_unit": "2", "symbol": "KM", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "BWP": { "name": "Pula", @@ -499,7 +434,7 @@ "name": "Cabo Verde Escudo", "numeric_code": "132", "minor_unit": "2", - "symbol": "$", + "symbol": "CVE", "physical_currency_denominations": [ "200", "500", @@ -530,7 +465,7 @@ "name": "CFA Franc BEAC", "numeric_code": "950", "minor_unit": "0", - "symbol": "CFA", + "symbol": "FCFA", "physical_currency_denominations": [ "500", "1000", @@ -546,34 +481,21 @@ "name": "Canadian Dollar", "numeric_code": "124", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "CA$", + "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "KYD": { "name": "Cayman Islands Dollar", "numeric_code": "136", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "symbol": "CI$", + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "CLP": { "name": "Chilean Peso", "numeric_code": "152", "minor_unit": "0", - "symbol": "$", + "symbol": "CLP", "physical_currency_denominations": [ "1", "5", @@ -591,15 +513,13 @@ "numeric_code": "990", "minor_unit": "4", "symbol": "UF", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "CNY": { "name": "Yuan Renminbi", "numeric_code": "156", "minor_unit": "2", - "symbol": "¥", + "symbol": "CN¥", "physical_currency_denominations": [ "1", "2", @@ -614,7 +534,7 @@ "name": "Colombian Peso", "numeric_code": "170", "minor_unit": "2", - "symbol": "$", + "symbol": "COL$", "physical_currency_denominations": [ "1000", "2000", @@ -629,9 +549,7 @@ "numeric_code": "970", "minor_unit": "2", "symbol": "UVR", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "KMF": { "name": "Comorian Franc", @@ -671,14 +589,8 @@ "name": "New Zealand Dollar", "numeric_code": "554", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20" - ] + "symbol": "NZ$", + "physical_currency_denominations": ["1", "2", "5", "10", "20"] }, "CRC": { "name": "Costa Rican Colon", @@ -719,15 +631,8 @@ "name": "Cuban Peso", "numeric_code": "192", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "1", - "3", - "5", - "10", - "20", - "50" - ] + "symbol": "$MN", + "physical_currency_denominations": ["1", "3", "5", "10", "20", "50"] }, "CUC": { "name": "Peso Convertible", @@ -789,56 +694,34 @@ "numeric_code": "208", "minor_unit": "2", "symbol": "kr", - "physical_currency_denominations": [ - "50", - "100", - "200", - "500", - "1000" - ] + "physical_currency_denominations": ["50", "100", "200", "500", "1000"] }, "DJF": { "name": "Djibouti Franc", "numeric_code": "262", "minor_unit": "0", "symbol": "Fdj", - "physical_currency_denominations": [ - "1000", - "2000", - "5000", - "10000" - ] + "physical_currency_denominations": ["1000", "2000", "5000", "10000"] }, "DOP": { "name": "Dominican Peso", "numeric_code": "214", "minor_unit": "2", "symbol": "RD$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50"] }, "EGP": { "name": "Egyptian Pound", "numeric_code": "818", "minor_unit": "2", - "symbol": "£", - "physical_currency_denominations": [ - "25", - "50", - "100", - "200" - ] + "symbol": "E£", + "physical_currency_denominations": ["25", "50", "100", "200"] }, "SVC": { "name": "El Salvador Colon", "numeric_code": "222", "minor_unit": "2", - "symbol": "$", + "symbol": "₡", "physical_currency_denominations": [ "0.01", "0.05", @@ -858,89 +741,49 @@ "numeric_code": "232", "minor_unit": "2", "symbol": "Nfk", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "SZL": { "name": "Lilangeni", "numeric_code": "748", "minor_unit": "2", "symbol": "E", - "physical_currency_denominations": [ - "2" - ] + "physical_currency_denominations": ["2"] }, "ETB": { "name": "Ethiopian Birr", "numeric_code": "230", "minor_unit": "2", "symbol": "Br", - "physical_currency_denominations": [ - "1", - "5", - "10", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "50", "100"] }, "FKP": { "name": "Falkland Islands Pound", "numeric_code": "238", "minor_unit": "2", - "symbol": "£", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20", - "50" - ] + "symbol": "FK£", + "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "FJD": { "name": "Fiji Dollar", "numeric_code": "242", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "2", - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "FJ$", + "physical_currency_denominations": ["2", "5", "10", "20", "50", "100"] }, "XPF": { "name": "CFP Franc", "numeric_code": "953", "minor_unit": "0", "symbol": "F", - "physical_currency_denominations": [ - "500", - "1000", - "2000", - "5000" - ] + "physical_currency_denominations": ["500", "1000", "2000", "5000"] }, "GMD": { "name": "Dalasi", "numeric_code": "270", "minor_unit": "2", "symbol": "D", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "GEL": { "name": "Lari", @@ -963,56 +806,28 @@ "numeric_code": "936", "minor_unit": "2", "symbol": "GH₵", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "GIP": { "name": "Gibraltar Pound", "numeric_code": "292", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["5", "10", "20", "50", "100", "200"] }, "GTQ": { "name": "Quetzal", "numeric_code": "320", "minor_unit": "2", "symbol": "Q", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "GBP": { "name": "Pound Sterling", "numeric_code": "826", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "GNF": { "name": "Guinean Franc", @@ -1034,7 +849,7 @@ "name": "Guyana Dollar", "numeric_code": "328", "minor_unit": "2", - "symbol": "$", + "symbol": "GY$", "physical_currency_denominations": [ "20", "100", @@ -1081,7 +896,7 @@ "name": "Hong Kong Dollar", "numeric_code": "344", "minor_unit": "2", - "symbol": "$", + "symbol": "HK$", "physical_currency_denominations": [ "10", "20", @@ -1182,50 +997,28 @@ "numeric_code": "376", "minor_unit": "2", "symbol": "₪", - "physical_currency_denominations": [ - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["20", "50", "100", "200"] }, "JMD": { "name": "Jamaican Dollar", "numeric_code": "388", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "50", - "100", - "500", - "1000", - "5000" - ] + "symbol": "J$", + "physical_currency_denominations": ["50", "100", "500", "1000", "5000"] }, "JPY": { "name": "Yen", "numeric_code": "392", "minor_unit": "0", "symbol": "¥", - "physical_currency_denominations": [ - "1000", - "2000", - "5000", - "10000" - ] + "physical_currency_denominations": ["1000", "2000", "5000", "10000"] }, "JOD": { "name": "Jordanian Dinar", "numeric_code": "400", "minor_unit": "3", "symbol": "JD", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "KZT": { "name": "Tenge", @@ -1249,25 +1042,14 @@ "numeric_code": "404", "minor_unit": "2", "symbol": "KSh", - "physical_currency_denominations": [ - "50", - "100", - "200", - "500", - "1000" - ] + "physical_currency_denominations": ["50", "100", "200", "500", "1000"] }, "KPW": { "name": "North Korean Won", "numeric_code": "408", "minor_unit": "2", "symbol": "₩", - "physical_currency_denominations": [ - "5", - "10", - "50", - "100" - ] + "physical_currency_denominations": ["5", "10", "50", "100"] }, "KRW": { "name": "Won", @@ -1287,14 +1069,7 @@ "numeric_code": "414", "minor_unit": "3", "symbol": "د.ك", - "physical_currency_denominations": [ - "0.25", - "0.5", - "1", - "5", - "10", - "20" - ] + "physical_currency_denominations": ["0.25", "0.5", "1", "5", "10", "20"] }, "KGS": { "name": "Som", @@ -1332,18 +1107,14 @@ "name": "Lebanese Pound", "numeric_code": "422", "minor_unit": "2", - "symbol": "£", - "physical_currency_denominations": [ - "25000", - "50000", - "100000" - ] + "symbol": "L£", + "physical_currency_denominations": ["25000", "50000", "100000"] }, "LSL": { "name": "Loti", "numeric_code": "426", "minor_unit": "2", - "symbol": "L", + "symbol": "M", "physical_currency_denominations": [ "1", "2", @@ -1361,40 +1132,21 @@ "numeric_code": "710", "minor_unit": "2", "symbol": "R", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "LRD": { "name": "Liberian Dollar", "numeric_code": "430", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100", - "500" - ] + "symbol": "L$", + "physical_currency_denominations": ["5", "10", "20", "50", "100", "500"] }, "LYD": { "name": "Libyan Dinar", "numeric_code": "434", "minor_unit": "3", "symbol": "LD", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "CHF": { "name": "Swiss Franc", @@ -1414,14 +1166,8 @@ "name": "Pataca", "numeric_code": "446", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "500" - ] + "symbol": "MOP$", + "physical_currency_denominations": ["10", "20", "50", "100", "500"] }, "MKD": { "name": "Denar", @@ -1480,14 +1226,7 @@ "numeric_code": "458", "minor_unit": "2", "symbol": "RM", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "MVR": { "name": "Rufiyaa", @@ -1541,23 +1280,15 @@ "name": "Mexican Peso", "numeric_code": "484", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "20", - "50", - "100", - "200", - "500" - ] + "symbol": "Mex$", + "physical_currency_denominations": ["20", "50", "100", "200", "500"] }, "MXV": { "name": "Mexican Unidad de Inversion (UDI)", "numeric_code": "979", "minor_unit": "2", - "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "symbol": "UDI", + "physical_currency_denominations": ["nan"] }, "MDL": { "name": "Moldovan Leu", @@ -1600,12 +1331,7 @@ "numeric_code": "504", "minor_unit": "2", "symbol": "DH", - "physical_currency_denominations": [ - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["20", "50", "100", "200"] }, "MZN": { "name": "Mozambique Metical", @@ -1640,14 +1366,8 @@ "name": "Namibia Dollar", "numeric_code": "516", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "symbol": "N$", + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "NPR": { "name": "Nepalese Rupee", @@ -1702,13 +1422,7 @@ "numeric_code": "512", "minor_unit": "3", "symbol": "ر.ع.", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "PKR": { "name": "Pakistan Rupee", @@ -1729,28 +1443,14 @@ "numeric_code": "590", "minor_unit": "2", "symbol": "B/.", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "PGK": { "name": "Kina", "numeric_code": "598", "minor_unit": "2", "symbol": "K", - "physical_currency_denominations": [ - "2", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["2", "5", "10", "20", "50", "100"] }, "PYG": { "name": "Guarani", @@ -1771,13 +1471,7 @@ "numeric_code": "604", "minor_unit": "2", "symbol": "S/", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "PHP": { "name": "Philippine Peso", @@ -1798,40 +1492,21 @@ "numeric_code": "985", "minor_unit": "2", "symbol": "zł", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "QAR": { "name": "Qatari Rial", "numeric_code": "634", "minor_unit": "2", "symbol": "ر.ق", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "25", "50"] }, "RON": { "name": "Romanian Leu", "numeric_code": "946", "minor_unit": "2", "symbol": "lei", - "physical_currency_denominations": [ - "1", - "5", - "10", - "50", - "100", - "200" - ] + "physical_currency_denominations": ["1", "5", "10", "50", "100", "200"] }, "RUB": { "name": "Russian Ruble", @@ -1853,62 +1528,35 @@ "numeric_code": "646", "minor_unit": "0", "symbol": "FRw", - "physical_currency_denominations": [ - "500", - "1000", - "2000", - "5000" - ] + "physical_currency_denominations": ["500", "1000", "2000", "5000"] }, "SHP": { "name": "Saint Helena Pound", "numeric_code": "654", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["5", "10", "20", "50"] }, "WST": { "name": "Tala", "numeric_code": "882", "minor_unit": "2", - "symbol": "T", - "physical_currency_denominations": [ - "10", - "20", - "50", - "100" - ] + "symbol": "WS$", + "physical_currency_denominations": ["10", "20", "50", "100"] }, "STN": { "name": "Dobra", "numeric_code": "930", "minor_unit": "2", "symbol": "Db", - "physical_currency_denominations": [ - "100", - "200", - "500", - "1000" - ] + "physical_currency_denominations": ["100", "200", "500", "1000"] }, "SAR": { "name": "Saudi Riyal", "numeric_code": "682", "minor_unit": "2", "symbol": "ر.س", - "physical_currency_denominations": [ - "1", - "5", - "10", - "50", - "100", - "500" - ] + "physical_currency_denominations": ["1", "5", "10", "50", "100", "500"] }, "RSD": { "name": "Serbian Dinar", @@ -1931,13 +1579,7 @@ "numeric_code": "690", "minor_unit": "2", "symbol": "₨", - "physical_currency_denominations": [ - "10", - "25", - "50", - "100", - "500" - ] + "physical_currency_denominations": ["10", "25", "50", "100", "500"] }, "SLL": { "name": "Leone", @@ -1959,53 +1601,28 @@ "numeric_code": "702", "minor_unit": "2", "symbol": "S$", - "physical_currency_denominations": [ - "2", - "5", - "10", - "50", - "100", - "1000" - ] + "physical_currency_denominations": ["2", "5", "10", "50", "100", "1000"] }, "SBD": { "name": "Solomon Islands Dollar", "numeric_code": "90", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "SI$", + "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "SOS": { "name": "Somali Shilling", "numeric_code": "706", "minor_unit": "2", "symbol": "S", - "physical_currency_denominations": [ - "500", - "1000", - "5000", - "10000" - ] + "physical_currency_denominations": ["500", "1000", "5000", "10000"] }, "SSP": { "name": "South Sudanese Pound", "numeric_code": "728", "minor_unit": "2", - "symbol": "£", - "physical_currency_denominations": [ - "1", - "5", - "10", - "25", - "50", - "100" - ] + "symbol": "SS£", + "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "LKR": { "name": "Sri Lanka Rupee", @@ -2043,14 +1660,8 @@ "name": "Surinam Dollar", "numeric_code": "968", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "SRD", + "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "SEK": { "name": "Swedish Krona", @@ -2072,44 +1683,28 @@ "numeric_code": "947", "minor_unit": "2", "symbol": "CHE", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "CHW": { "name": "WIR Franc", "numeric_code": "948", "minor_unit": "2", "symbol": "CHW", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "SYP": { "name": "Syrian Pound", "numeric_code": "760", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "50", - "100", - "200", - "500", - "1000" - ] + "physical_currency_denominations": ["50", "100", "200", "500", "1000"] }, "TWD": { "name": "New Taiwan Dollar", "numeric_code": "901", "minor_unit": "2", "symbol": "NT$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50"] }, "TJS": { "name": "Somoni", @@ -2144,53 +1739,28 @@ "numeric_code": "764", "minor_unit": "2", "symbol": "฿", - "physical_currency_denominations": [ - "20", - "50", - "100", - "500", - "1000" - ] + "physical_currency_denominations": ["20", "50", "100", "500", "1000"] }, "TOP": { "name": "Pa’anga", "numeric_code": "776", "minor_unit": "2", "symbol": "T$", - "physical_currency_denominations": [ - "1", - "2", - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "TTD": { "name": "Trinidad and Tobago Dollar", "numeric_code": "780", "minor_unit": "2", "symbol": "TT$", - "physical_currency_denominations": [ - "1", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "TND": { "name": "Tunisian Dinar", "numeric_code": "788", "minor_unit": "3", "symbol": "DT", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50" - ] + "physical_currency_denominations": ["5", "10", "20", "50"] }, "TRY": { "name": "Turkish Lira", @@ -2273,10 +1843,8 @@ "name": "Uruguay Peso en Unidades Indexadas (URUIURUI)", "numeric_code": "858", "minor_unit": "2", - "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "symbol": "$U", + "physical_currency_denominations": ["nan"] }, "UYU": { "name": "Peso Uruguayo", @@ -2298,10 +1866,8 @@ "name": "Unidad Previsional", "numeric_code": "927", "minor_unit": "4", - "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "symbol": "UR", + "physical_currency_denominations": ["nan"] }, "UZS": { "name": "Uzbekistan Sum", @@ -2338,28 +1904,14 @@ "numeric_code": "928", "minor_unit": "2", "symbol": "Bs.S.", - "physical_currency_denominations": [ - "2", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["2", "5", "10", "20", "50", "100"] }, "VED": { "name": "Bolívar Soberano", "numeric_code": "926", "minor_unit": "2", "symbol": "Bs.S.", - "physical_currency_denominations": [ - "2", - "5", - "10", - "20", - "50", - "100" - ] + "physical_currency_denominations": ["2", "5", "10", "20", "50", "100"] }, "VND": { "name": "Dong", @@ -2383,13 +1935,7 @@ "numeric_code": "886", "minor_unit": "2", "symbol": "﷼", - "physical_currency_denominations": [ - "200", - "500", - "1000", - "2000", - "5000" - ] + "physical_currency_denominations": ["200", "500", "1000", "2000", "5000"] }, "ZMW": { "name": "Zambian Kwacha", @@ -2410,7 +1956,7 @@ "name": "Zimbabwe Dollar", "numeric_code": "932", "minor_unit": "2", - "symbol": "$", + "symbol": "Z$", "physical_currency_denominations": [ "1", "5", @@ -2424,4 +1970,4 @@ ] } } -} \ No newline at end of file +} diff --git a/packages/i18nify-js/src/modules/currency/__tests__/formatNumber.test.ts b/packages/i18nify-js/src/modules/currency/__tests__/formatNumber.test.ts index 37070d85..5ffe7a2e 100644 --- a/packages/i18nify-js/src/modules/currency/__tests__/formatNumber.test.ts +++ b/packages/i18nify-js/src/modules/currency/__tests__/formatNumber.test.ts @@ -166,4 +166,63 @@ describe('formatNumber', () => { ), ); }); + + const intlMappedTestCases = [ + ['SGD', 'en-SG', 'S$123,456.33'], + ['XCD', 'en-AI', 'EC$123,456.33'], + ['ARS', 'en-AR', `ARS${nbsp}123,456.33`], + ['AUD', 'en-AU', 'A$123,456.33'], + ['BSD', 'en-BS', 'BSD123,456.33'], + ['BBD', 'en-BB', 'Bds$123,456.33'], + ['BMD', 'en-BM', 'BD$123,456.33'], + ['CVE', 'en-CV', `CVE${nbsp}123,456.33`], + ['CAD', 'en-CA', 'CA$123,456.33'], + ['KYD', 'en-KY', 'CI$123,456.33'], + ['CLP', 'en-CL', `CLP${nbsp}123,456`], + ['COP', 'en-CO', `COP${nbsp}123,456.33`], + ['NZD', 'en-CK', 'NZ$123,456.33'], + ['CUP', 'en-CU', `CUP${nbsp}123,456.33`], + ['SVC', 'en-SV', `SVC${nbsp}123,456.33`], + ['FJD', 'en-FJ', 'FJ$123,456.33'], + ['GYD', 'en-GY', 'GY$123,456.33'], + ['HKD', 'en-HK', 'HK$123,456.33'], + ['JMD', 'en-JM', 'J$123,456.33'], + ['LRD', 'en-LR', 'L$123,456.33'], + ['MOP', 'en', `MOP${nbsp}123,456.33`], + ['MXN', 'en-MX', 'MX$123,456.33'], + ['NAD', 'en-NA', 'N$123,456.33'], + ['SBD', 'en-SB', 'SI$123,456.33'], + ['SRD', 'en-SR', `SRD${nbsp}123,456.33`], + ['ZWL', 'en-ZW', `ZWL${nbsp}123,456.33`], + ['LSL', 'en-LS', `LSL${nbsp}123,456.33`], + ['AWG', 'en-AW', `AWG${nbsp}123,456.33`], + ['BYN', 'en', `BYN${nbsp}123,456.33`], + ['XAF', 'en-CM', `FCFA${nbsp}123,456`], + ['CNY', 'en-CN', `CN¥123,456.33`], + ['EGP', 'en-EG', `EGP${nbsp}123,456.33`], + ['FKP', 'en-FK', `FK£123,456.33`], + ['LBP', 'en-LB', `LBP${nbsp}123,456`], + ['SSP', 'en', `SSP${nbsp}123,456.33`], + ['WST', 'en-WS', `WS$123,456.33`], + ]; + + it.each(intlMappedTestCases)( + 'formats (+ve and -ve) amount 123456.3276 with currency "%s", locale "%s" to "%s"', + (currency, locale, expected) => { + const amount = 123456.3276; + expect( + formatNumber(amount, { + currency: currency as CurrencyCodeType, + locale: locale as string, + }), + ).toBe(expected); + + expect( + formatNumber(-amount, { + currency: currency as CurrencyCodeType, + locale: locale as string, + }), + ).toBe(`-${expected}`); + }, + ); }); diff --git a/packages/i18nify-js/src/modules/currency/__tests__/formatNumberByParts.test.ts b/packages/i18nify-js/src/modules/currency/__tests__/formatNumberByParts.test.ts index a188e5be..1f9dadd8 100644 --- a/packages/i18nify-js/src/modules/currency/__tests__/formatNumberByParts.test.ts +++ b/packages/i18nify-js/src/modules/currency/__tests__/formatNumberByParts.test.ts @@ -1,7 +1,16 @@ import { CurrencyCodeType, formatNumberByParts } from '../index'; +import { numberPartsIntlMap } from './mocks/formatNumberToParts'; const nbsp = String.fromCharCode(160); +const addMinusSignInMock = (mock: any) => { + return { + ...mock, + minusSign: '-', + rawParts: [{ type: 'minusSign', value: '-' }, ...mock.rawParts], + }; +}; + describe('formatNumberByParts', () => { it('should format the amount correctly for a given currency', () => { const result = formatNumberByParts(12345.67, { @@ -263,4 +272,67 @@ describe('formatNumberByParts', () => { true, ); }); + + const intlMappedTestCases = [ + ['SGD', 'en-SG'], + ['XCD', 'en-AI'], + ['ARS', 'en-AR'], + ['AUD', 'en-AU'], + ['BSD', 'en-BS'], + ['BBD', 'en-BB'], + ['BMD', 'en-BM'], + ['CVE', 'en-CV'], + ['CAD', 'en-CA'], + ['KYD', 'en-KY'], + ['CLP', 'en-CL'], + ['COP', 'en-CO'], + ['NZD', 'en-CK'], + ['CUP', 'en-CU'], + ['SVC', 'en-SV'], + ['FJD', 'en-FJ'], + ['GYD', 'en-GY'], + ['HKD', 'en-HK'], + ['JMD', 'en-JM'], + ['LRD', 'en-LR'], + ['MOP', 'en'], + ['MXN', 'en-MX'], + ['NAD', 'en-NA'], + ['SBD', 'en-SB'], + ['SRD', 'en-SR'], + ['ZWL', 'en-ZW'], + ['LSL', 'en-LS'], + ['AWG', 'en-AW'], + ['BYN', 'en'], + ['XAF', 'en-CM'], + ['CNY', 'en-CN'], + ['EGP', 'en-EG'], + ['FKP', 'en-FK'], + ['LBP', 'en-LB'], + ['SSP', 'en'], + ['WST', 'en-WS'], + ]; + + it.each(intlMappedTestCases)( + 'parses (+ve and -ve) amount 123456.3276 with currency "%s", locale "%s" to "%s"', + (currency, locale) => { + const amount = 123456.3276; + const positiveMock = + numberPartsIntlMap[currency as keyof typeof numberPartsIntlMap]; + const negativeMock = addMinusSignInMock(positiveMock); + + expect( + formatNumberByParts(amount, { + currency: currency as CurrencyCodeType, + locale: locale as string, + }), + ).toEqual(positiveMock); + + expect( + formatNumberByParts(-amount, { + currency: currency as CurrencyCodeType, + locale: locale as string, + }), + ).toEqual(negativeMock); + }, + ); }); diff --git a/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts b/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts new file mode 100644 index 00000000..dd0a2e0d --- /dev/null +++ b/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts @@ -0,0 +1,548 @@ +const nbsp = String.fromCharCode(160); + +export const numberPartsIntlMap = { + SGD: { + currency: 'S$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'S$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + XCD: { + currency: 'EC$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'EC$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + ARS: { + currency: 'ARS', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'ARS' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + AUD: { + currency: 'A$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'A$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + BSD: { + currency: 'BSD', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'BSD' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + BBD: { + currency: 'Bds$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'Bds$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + BMD: { + currency: 'BD$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'BD$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + CVE: { + currency: 'CVE', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'CVE' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + CAD: { + currency: 'CA$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'CA$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + KYD: { + currency: 'CI$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'CI$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + CLP: { + currency: 'CLP', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'CLP' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + ], + }, + COP: { + currency: 'COP', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'COP' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + NZD: { + currency: 'NZ$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'NZ$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + CUP: { + currency: 'CUP', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'CUP' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + SVC: { + currency: 'SVC', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'SVC' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + FJD: { + currency: 'FJ$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'FJ$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + GYD: { + currency: 'GY$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'GY$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + HKD: { + currency: 'HK$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'HK$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + JMD: { + currency: 'J$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'J$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + LRD: { + currency: 'L$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'L$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + MOP: { + currency: 'MOP', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'MOP' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + MXN: { + currency: 'MX$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'MX$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + NAD: { + currency: 'N$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'N$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + SBD: { + currency: 'SI$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'SI$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + SRD: { + currency: 'SRD', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'SRD' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + ZWL: { + currency: 'ZWL', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'ZWL' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + LSL: { + currency: 'LSL', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'LSL' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + AWG: { + currency: 'AWG', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'AWG' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + BYN: { + currency: 'BYN', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'BYN' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + XAF: { + currency: 'FCFA', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'FCFA' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + ], + }, + CNY: { + currency: 'CN¥', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'CN¥' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + EGP: { + currency: 'EGP', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'EGP' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + FKP: { + currency: 'FK£', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'FK£' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + LBP: { + currency: 'LBP', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'LBP' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + ], + }, + SSP: { + currency: 'SSP', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'SSP' }, + { type: 'literal', value: `${nbsp}` }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, + WST: { + currency: 'WS$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'WS$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, +}; diff --git a/packages/i18nify-js/src/modules/currency/__tests__/mocks/transformPartsFromIntl.ts b/packages/i18nify-js/src/modules/currency/__tests__/mocks/transformPartsFromIntl.ts new file mode 100644 index 00000000..c302142e --- /dev/null +++ b/packages/i18nify-js/src/modules/currency/__tests__/mocks/transformPartsFromIntl.ts @@ -0,0 +1,8 @@ +import { ByParts } from '../../types'; + +export const getMockParts = (symbol: string): ByParts['rawParts'] => [ + { type: 'currency', value: symbol }, + { type: 'integer', value: '1000' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '00' }, +]; diff --git a/packages/i18nify-js/src/modules/currency/__tests__/transformPartsFromIntl.test.ts b/packages/i18nify-js/src/modules/currency/__tests__/transformPartsFromIntl.test.ts new file mode 100644 index 00000000..720011af --- /dev/null +++ b/packages/i18nify-js/src/modules/currency/__tests__/transformPartsFromIntl.test.ts @@ -0,0 +1,46 @@ +import { INTL_MAPPING } from '../constants'; +import { ByParts } from '../types'; +import { transformPartsFromIntl } from '../utils'; +import { getMockParts } from './mocks/transformPartsFromIntl'; + +describe('transformPartsFromIntl', () => { + Object.keys(INTL_MAPPING).forEach((currencyCode) => { + const mapping = INTL_MAPPING[currencyCode as keyof typeof INTL_MAPPING]; + const symbolKey = Object.keys(mapping)[0] as keyof typeof mapping; + const mockParts = getMockParts(symbolKey as string); + const expectedParts = [ + { type: 'currency', value: mapping[symbolKey] }, + { type: 'integer', value: '1000' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '00' }, + ]; + + it(`should replace the currency symbol with the value from INTL_MAPPING for ${currencyCode}`, () => { + const result = transformPartsFromIntl(mockParts, currencyCode); + expect(result).toEqual(expectedParts); + }); + }); + + it('should not modify parts if currency code is not in INTL_MAPPING', () => { + const currencyCode = 'XYZ'; + const mockParts = getMockParts('$'); + const result = transformPartsFromIntl(mockParts, currencyCode); + expect(result).toEqual(mockParts); + }); + + it('should not modify parts if there is no matching value in INTL_MAPPING', () => { + const mockPartsWithDifferentCurrencySymbol: ByParts['rawParts'] = [ + { type: 'currency', value: '€' }, + { type: 'integer', value: '1000' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '00' }, + ]; + + const currencyCode = 'SGD'; + const result = transformPartsFromIntl( + mockPartsWithDifferentCurrencySymbol, + currencyCode, + ); + expect(result).toEqual(mockPartsWithDifferentCurrencySymbol); + }); +}); diff --git a/packages/i18nify-js/src/modules/currency/constants.ts b/packages/i18nify-js/src/modules/currency/constants.ts index 6ca5e844..e39abf59 100644 --- a/packages/i18nify-js/src/modules/currency/constants.ts +++ b/packages/i18nify-js/src/modules/currency/constants.ts @@ -1,3 +1,5 @@ +import CURRENCY_INFO from './data/currencyConfig.json'; + export const ALLOWED_FORMAT_PARTS_KEYS = [ 'nan', 'infinity', @@ -19,3 +21,42 @@ export const ALLOWED_FORMAT_PARTS_KEYS = [ 'exponentSeparator', 'unit', ] as const; + +export const INTL_MAPPING = { + SGD: { $: CURRENCY_INFO.SGD.symbol }, // Singapore Dollar + XCD: { $: CURRENCY_INFO.XCD.symbol }, // East Caribbean Dollar + ARS: { $: CURRENCY_INFO.ARS.symbol }, // Argentine Peso + AUD: { $: CURRENCY_INFO.AUD.symbol }, // Australian Dollar + BSD: { $: CURRENCY_INFO.BSD.symbol }, // Bahamian Dollar + BBD: { $: CURRENCY_INFO.BBD.symbol }, // Barbados Dollar + BMD: { $: CURRENCY_INFO.BMD.symbol }, // Bermudian Dollar + CVE: { $: CURRENCY_INFO.CVE.symbol }, // Cabo Verde Escudo + CAD: { $: CURRENCY_INFO.CAD.symbol }, // Canadian Dollar + KYD: { $: CURRENCY_INFO.KYD.symbol }, // Cayman Islands Dollar + CLP: { $: CURRENCY_INFO.CLP.symbol }, // Chilean Peso + COP: { $: CURRENCY_INFO.COP.symbol }, // Colombian Peso + NZD: { $: CURRENCY_INFO.NZD.symbol }, // New Zealand Dollar + CUP: { $: CURRENCY_INFO.CUP.symbol }, // Cuban Peso + SVC: { $: CURRENCY_INFO.SVC.symbol }, // El Salvador Colon + FJD: { $: CURRENCY_INFO.FJD.symbol }, // Fiji Dollar + GYD: { $: CURRENCY_INFO.GYD.symbol }, // Guyana Dollar + HKD: { $: CURRENCY_INFO.HKD.symbol }, // Hong Kong Dollar + JMD: { $: CURRENCY_INFO.JMD.symbol }, // Jamaican Dollar + LRD: { $: CURRENCY_INFO.LRD.symbol }, // Liberian Dollar + MOP: { $: CURRENCY_INFO.MOP.symbol }, // Pataca + MXN: { $: CURRENCY_INFO.MXN.symbol }, // Mexican Peso + NAD: { $: CURRENCY_INFO.NAD.symbol }, // Namibia Dollar + SBD: { $: CURRENCY_INFO.SBD.symbol }, // Solomon Islands Dollar + SRD: { $: CURRENCY_INFO.SRD.symbol }, // Surinam Dollar + ZWL: { $: CURRENCY_INFO.ZWL.symbol }, // Zimbabwe Dollar + LSL: { L: CURRENCY_INFO.LSL.symbol }, // Loti + AWG: { 'Afl.': CURRENCY_INFO.AWG.symbol }, // Aruban Florin + BYN: { Br: CURRENCY_INFO.BYN.symbol }, // Belarusian Ruble + XAF: { FCFA: CURRENCY_INFO.XAF.symbol }, // CFA Franc BEAC + CNY: { '¥': CURRENCY_INFO.CNY.symbol }, // Yuan Renminbi + EGP: { '£': CURRENCY_INFO.EGP.symbol }, // Egyptian Pound + FKP: { '£': CURRENCY_INFO.FKP.symbol }, // Falkland Islands Pound + LBP: { '£': CURRENCY_INFO.LBP.symbol }, // Lebanese Pound + SSP: { '£': CURRENCY_INFO.SSP.symbol }, // South Sudanese Pound + WST: { T: CURRENCY_INFO.WST.symbol }, // Tala +}; diff --git a/packages/i18nify-js/src/modules/currency/data/currencyConfig.json b/packages/i18nify-js/src/modules/currency/data/currencyConfig.json index 4c25b3ed..9db019f4 100644 --- a/packages/i18nify-js/src/modules/currency/data/currencyConfig.json +++ b/packages/i18nify-js/src/modules/currency/data/currencyConfig.json @@ -32,12 +32,12 @@ "XCD": { "name": "East Caribbean Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "EC$" }, "ARS": { "name": "Argentine Peso", "minor_unit": "2", - "symbol": "$" + "symbol": "ARS" }, "AMD": { "name": "Armenian Dram", @@ -47,12 +47,12 @@ "AWG": { "name": "Aruban Florin", "minor_unit": "2", - "symbol": "ƒ" + "symbol": "Aƒ" }, "AUD": { "name": "Australian Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "A$" }, "AZN": { "name": "Azerbaijan Manat", @@ -62,7 +62,7 @@ "BSD": { "name": "Bahamian Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "BSD" }, "BHD": { "name": "Bahraini Dinar", @@ -77,12 +77,12 @@ "BBD": { "name": "Barbados Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "Bds$" }, "BYN": { "name": "Belarusian Ruble", "minor_unit": "2", - "symbol": "Br" + "symbol": "Rbl" }, "BZD": { "name": "Belize Dollar", @@ -97,7 +97,7 @@ "BMD": { "name": "Bermudian Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "BD$" }, "INR": { "name": "Indian Rupee", @@ -117,7 +117,7 @@ "BOV": { "name": "Mvdol", "minor_unit": "2", - "symbol": "nan" + "symbol": "Bs" }, "BAM": { "name": "Convertible Mark", @@ -157,7 +157,7 @@ "CVE": { "name": "Cabo Verde Escudo", "minor_unit": "2", - "symbol": "$" + "symbol": "CVE" }, "KHR": { "name": "Riel", @@ -167,22 +167,22 @@ "XAF": { "name": "CFA Franc BEAC", "minor_unit": "0", - "symbol": "CFA" + "symbol": "FCFA" }, "CAD": { "name": "Canadian Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "CA$" }, "KYD": { "name": "Cayman Islands Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "CI$" }, "CLP": { "name": "Chilean Peso", "minor_unit": "0", - "symbol": "$" + "symbol": "CLP" }, "CLF": { "name": "Unidad de Fomento", @@ -192,12 +192,12 @@ "CNY": { "name": "Yuan Renminbi", "minor_unit": "2", - "symbol": "¥" + "symbol": "CN¥" }, "COP": { "name": "Colombian Peso", "minor_unit": "2", - "symbol": "$" + "symbol": "COL$" }, "COU": { "name": "Unidad de Valor Real", @@ -217,7 +217,7 @@ "NZD": { "name": "New Zealand Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "NZ$" }, "CRC": { "name": "Costa Rican Colon", @@ -232,7 +232,7 @@ "CUP": { "name": "Cuban Peso", "minor_unit": "2", - "symbol": "$" + "symbol": "$MN" }, "CUC": { "name": "Peso Convertible", @@ -267,12 +267,12 @@ "EGP": { "name": "Egyptian Pound", "minor_unit": "2", - "symbol": "£" + "symbol": "E£" }, "SVC": { "name": "El Salvador Colon", "minor_unit": "2", - "symbol": "$" + "symbol": "₡" }, "ERN": { "name": "Nakfa", @@ -292,12 +292,12 @@ "FKP": { "name": "Falkland Islands Pound", "minor_unit": "2", - "symbol": "£" + "symbol": "FK£" }, "FJD": { "name": "Fiji Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "FJ$" }, "XPF": { "name": "CFP Franc", @@ -342,7 +342,7 @@ "GYD": { "name": "Guyana Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "GY$" }, "HTG": { "name": "Gourde", @@ -357,7 +357,7 @@ "HKD": { "name": "Hong Kong Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "HK$" }, "HUF": { "name": "Forint", @@ -392,7 +392,7 @@ "JMD": { "name": "Jamaican Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "J$" }, "JPY": { "name": "Yen", @@ -442,12 +442,12 @@ "LBP": { "name": "Lebanese Pound", "minor_unit": "2", - "symbol": "£" + "symbol": "L£" }, "LSL": { "name": "Loti", "minor_unit": "2", - "symbol": "L" + "symbol": "M" }, "ZAR": { "name": "South African Rand", @@ -457,7 +457,7 @@ "LRD": { "name": "Liberian Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "L$" }, "LYD": { "name": "Libyan Dinar", @@ -472,7 +472,7 @@ "MOP": { "name": "Pataca", "minor_unit": "2", - "symbol": "$" + "symbol": "MOP$" }, "MKD": { "name": "Denar", @@ -512,12 +512,12 @@ "MXN": { "name": "Mexican Peso", "minor_unit": "2", - "symbol": "$" + "symbol": "Mex$" }, "MXV": { "name": "Mexican Unidad de Inversion (UDI)", "minor_unit": "2", - "symbol": "nan" + "symbol": "UDI" }, "MDL": { "name": "Moldovan Leu", @@ -547,7 +547,7 @@ "NAD": { "name": "Namibia Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "N$" }, "NPR": { "name": "Nepalese Rupee", @@ -632,7 +632,7 @@ "WST": { "name": "Tala", "minor_unit": "2", - "symbol": "T" + "symbol": "WS$" }, "STN": { "name": "Dobra", @@ -667,7 +667,7 @@ "SBD": { "name": "Solomon Islands Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "SI$" }, "SOS": { "name": "Somali Shilling", @@ -677,7 +677,7 @@ "SSP": { "name": "South Sudanese Pound", "minor_unit": "2", - "symbol": "£" + "symbol": "SS£" }, "LKR": { "name": "Sri Lanka Rupee", @@ -692,7 +692,7 @@ "SRD": { "name": "Surinam Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "SRD" }, "SEK": { "name": "Swedish Krona", @@ -777,7 +777,7 @@ "UYI": { "name": "Uruguay Peso en Unidades Indexadas (URUIURUI)", "minor_unit": "2", - "symbol": "nan" + "symbol": "$U" }, "UYU": { "name": "Peso Uruguayo", @@ -787,7 +787,7 @@ "UYW": { "name": "Unidad Previsional", "minor_unit": "4", - "symbol": "nan" + "symbol": "UR" }, "UZS": { "name": "Uzbekistan Sum", @@ -827,6 +827,6 @@ "ZWL": { "name": "Zimbabwe Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "Z$" } } \ No newline at end of file diff --git a/packages/i18nify-js/src/modules/currency/formatNumber.ts b/packages/i18nify-js/src/modules/currency/formatNumber.ts index 4ceee221..8fb38c3e 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumber.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumber.ts @@ -1,6 +1,7 @@ import { withErrorBoundary } from '../../common/errorBoundary'; import { getIntlInstanceWithOptions } from '../.internal/utils'; -import { CurrencyCodeType, I18nifyNumberFormatOptions } from './types'; +import { ByParts, CurrencyCodeType, I18nifyNumberFormatOptions } from './types'; +import { transformPartsFromIntl } from './utils'; // this function formats number based on different arguments passed const formatNumber = ( @@ -11,17 +12,26 @@ const formatNumber = ( intlOptions?: I18nifyNumberFormatOptions; } = {}, ): string => { + // Validate the amount parameter to ensure it is a number if (!Number(amount) && Number(amount) !== 0) throw new Error( `Parameter 'amount' is not a number. typeof amount: ${typeof amount}`, ); - let formattedAmount = ''; - try { - formattedAmount = getIntlInstanceWithOptions(options).format( + // Get an instance of Intl.NumberFormat with the provided options + const formattedAmount = getIntlInstanceWithOptions(options).formatToParts( Number(amount), ); + + let parts: ByParts['rawParts'] = formattedAmount; + const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; + const currencyCode = (options?.currency || intlOptions.currency) as string; + + parts = transformPartsFromIntl(parts, currencyCode); + + // Join the parts back together to form the final formatted string + return parts.map((p) => p.value).join(''); } catch (err) { if (err instanceof Error) { throw new Error(err.message); @@ -29,8 +39,6 @@ const formatNumber = ( throw new Error(`An unknown error occurred = ${err}`); } } - - return formattedAmount; }; export default withErrorBoundary(formatNumber); diff --git a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts index 50b67b02..02e7f6ab 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts @@ -7,6 +7,7 @@ import { import { withErrorBoundary } from '../../common/errorBoundary'; import { getIntlInstanceWithOptions } from '../.internal/utils'; import { ALLOWED_FORMAT_PARTS_KEYS } from './constants'; +import { transformPartsFromIntl } from './utils'; const formatNumberByParts = ( amount: string | number, @@ -16,26 +17,33 @@ const formatNumberByParts = ( intlOptions?: I18nifyNumberFormatOptions; } = {}, ): ByParts => { + // Validate the amount parameter to ensure it is a number if (!Number(amount) && Number(amount) !== 0) throw new Error( `Parameter 'amount' is not a number. typeof amount: ${typeof amount}`, ); try { + // Get an instance of Intl.NumberFormat with the provided options const formattedAmount = getIntlInstanceWithOptions(options).formatToParts( Number(amount), ); - const parts = formattedAmount; - + let parts: ByParts['rawParts'] = formattedAmount; const formattedObj: FormattedPartsObject = {}; + const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; + const currencyCode = (options?.currency || intlOptions.currency) as string; + + parts = transformPartsFromIntl(parts, currencyCode); parts.forEach((p) => { + // If the part is a group separator, add it to the integer part if (p.type === 'group') { formattedObj.integer = (formattedObj.integer || '') + p.value; } else if ( ALLOWED_FORMAT_PARTS_KEYS.findIndex((item) => item === p.type) != -1 ) { + // If the part type is allowed, add it to the formatted object // @ts-expect-error only allowed keys are added to the formattedObj. For eg, key 'literal' is skipped formattedObj[p.type] = (formattedObj[p.type] || '') + p.value; } diff --git a/packages/i18nify-js/src/modules/currency/types.ts b/packages/i18nify-js/src/modules/currency/types.ts index d433c6ce..c0fa1b35 100644 --- a/packages/i18nify-js/src/modules/currency/types.ts +++ b/packages/i18nify-js/src/modules/currency/types.ts @@ -4,6 +4,7 @@ import CURRENCY_INFO from './data/currencyConfig.json'; export type FormattedPartsObject = { [key in (typeof ALLOWED_FORMAT_PARTS_KEYS)[number]]?: string | undefined; }; + export interface ByParts extends FormattedPartsObject { isPrefixSymbol: boolean; rawParts: Array<{ type: string; value: unknown }>; diff --git a/packages/i18nify-js/src/modules/currency/utils.ts b/packages/i18nify-js/src/modules/currency/utils.ts new file mode 100644 index 00000000..72f153da --- /dev/null +++ b/packages/i18nify-js/src/modules/currency/utils.ts @@ -0,0 +1,35 @@ +import { INTL_MAPPING } from './constants'; +import { ByParts } from './types'; + +/** + * This function replaces the default parameters like currency symbols, currency codes, etc., + * returned by the JavaScript Intl API with custom values provided by a local configuration + * (i18nify-data). This allows for customization of how different currencies or other locale-specific + * data are represented, providing greater control over the displayed formatting. + * + * @param {ByParts['rawParts']} parts - An array of parts representing the formatted components + * of a currency amount, as generated by Intl.NumberFormat. + * @param {string} currencyCode - The currency code (e.g., 'USD', 'EUR') for which the replacement + * values should be applied. + * @returns {ByParts['rawParts']} - The modified array of parts with replaced values based on the + * local i18nify configuration. + */ +export const transformPartsFromIntl = ( + parts: ByParts['rawParts'], + currencyCode: string, +): ByParts['rawParts'] => { + // Loop through each part of the formatted amount + for (let i = 0; i < parts.length; i++) { + const part = parts[i]; + + if (part.type === 'currency' && currencyCode in INTL_MAPPING) { + const mapping = INTL_MAPPING[currencyCode as keyof typeof INTL_MAPPING]; + if ((part.value as any) in mapping) { + parts[i].value = mapping[part.value as keyof typeof mapping]; + break; // Exit the loop after the first replacement + } + } + } + + return parts; +};