From e2d718c8089bd116eea54ca71525d2c9a1059807 Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Thu, 6 Jun 2024 18:55:03 +0530 Subject: [PATCH 01/14] [chore]: add logic to replace INTL currency symbol with the one in i18nify-data --- .../currency/__tests__/formatNumber.test.ts | 49 + .../__tests__/formatNumberByParts.test.ts | 61 ++ .../__tests__/mocks/formatNumberToParts.ts | 849 ++++++++++++++++++ .../src/modules/currency/constants.ts | 30 + .../src/modules/currency/formatNumber.ts | 22 +- .../modules/currency/formatNumberByParts.ts | 11 +- 6 files changed, 1016 insertions(+), 6 deletions(-) create mode 100644 packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts 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..e3beeee1 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,53 @@ 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', 'C$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`], + ]; + + 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..43ca3d29 100644 --- a/packages/i18nify-js/src/modules/currency/__tests__/formatNumberByParts.test.ts +++ b/packages/i18nify-js/src/modules/currency/__tests__/formatNumberByParts.test.ts @@ -1,4 +1,8 @@ import { CurrencyCodeType, formatNumberByParts } from '../index'; +import { + positiveNumberPartsIntlMap, + negativeNumberPartsIntlMap, +} from './mocks/formatNumberToParts'; const nbsp = String.fromCharCode(160); @@ -263,4 +267,61 @@ 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'], + ]; + + it.each(intlMappedTestCases)( + 'parses (+ve and -ve) amount 123456.3276 with currency "%s", locale "%s" to "%s"', + (currency, locale) => { + const amount = 123456.3276; + expect( + formatNumberByParts(amount, { + currency: currency as CurrencyCodeType, + locale: locale as string, + }), + ).toEqual( + positiveNumberPartsIntlMap[ + currency as keyof typeof positiveNumberPartsIntlMap + ], + ); + + expect( + formatNumberByParts(-amount, { + currency: currency as CurrencyCodeType, + locale: locale as string, + }), + ).toEqual( + negativeNumberPartsIntlMap[ + currency as keyof typeof negativeNumberPartsIntlMap + ], + ); + }, + ); }); 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..7780a4e9 --- /dev/null +++ b/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts @@ -0,0 +1,849 @@ +const nbsp = String.fromCharCode(160); + +export const positiveNumberPartsIntlMap = { + 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: 'C$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + rawParts: [ + { type: 'currency', value: 'C$' }, + { 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' }, + ], + }, +}; + +export const negativeNumberPartsIntlMap = { + SGD: { + currency: 'S$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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: 'C$', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { type: 'currency', value: 'C$' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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' }, + ], + }, +}; diff --git a/packages/i18nify-js/src/modules/currency/constants.ts b/packages/i18nify-js/src/modules/currency/constants.ts index 6ca5e844..00c17ef9 100644 --- a/packages/i18nify-js/src/modules/currency/constants.ts +++ b/packages/i18nify-js/src/modules/currency/constants.ts @@ -19,3 +19,33 @@ export const ALLOWED_FORMAT_PARTS_KEYS = [ 'exponentSeparator', 'unit', ] as const; + +// This has been taken from here: https://docs.google.com/spreadsheets/d/13VFVLJql-IPeIV5NTR5MNzeeJp5LVkelbt4jFGUpBlE/edit?usp=sharing +export const INTL_MAPPING = { + SGD: { $: 'S$' }, // Singapore Dollar + XCD: { $: 'EC$' }, // East Caribbean Dollar + ARS: { $: 'ARS' }, // Argentine Peso + AUD: { $: 'A$' }, // Australian Dollar + BSD: { $: 'BSD' }, // Bahamian Dollar + BBD: { $: 'Bds$' }, // Barbados Dollar + BMD: { $: 'BD$' }, // Bermudian Dollar + CVE: { $: 'CVE' }, // Cabo Verde Escudo + CAD: { $: 'C$' }, // Canadian Dollar + KYD: { $: 'CI$' }, // Cayman Islands Dollar + CLP: { $: 'CLP' }, // Chilean Peso + COP: { $: 'COL$' }, // Colombian Peso + NZD: { $: 'NZ$' }, // New Zealand Dollar + CUP: { $: '$MN' }, // Cuban Peso + SVC: { $: '₡' }, // El Salvador Colon + FJD: { $: 'FJ$' }, // Fiji Dollar + GYD: { $: 'GY$' }, // Guyana Dollar + HKD: { $: 'HK$' }, // Hong Kong Dollar + JMD: { $: 'J$' }, // Jamaican Dollar + LRD: { $: 'L$' }, // Liberian Dollar + MOP: { $: 'MOP$' }, // Pataca + MXN: { $: 'Mex$' }, // Mexican Peso + NAD: { $: 'N$' }, // Namibia Dollar + SBD: { $: 'SI$' }, // Solomon Islands Dollar + SRD: { $: 'SRD' }, // Surinam Dollar + ZWL: { $: 'Z$' }, // Zimbabwe Dollar +}; diff --git a/packages/i18nify-js/src/modules/currency/formatNumber.ts b/packages/i18nify-js/src/modules/currency/formatNumber.ts index 4ceee221..2c970c45 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 { INTL_MAPPING } from './constants'; // this function formats number based on different arguments passed const formatNumber = ( @@ -16,12 +17,25 @@ const formatNumber = ( `Parameter 'amount' is not a number. typeof amount: ${typeof amount}`, ); - let formattedAmount = ''; - try { - formattedAmount = getIntlInstanceWithOptions(options).format( + const formattedAmount = getIntlInstanceWithOptions(options).formatToParts( Number(amount), ); + + const parts: Array<{ type: string; value: unknown }> = formattedAmount; + const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; + const currencyCode = options?.currency || intlOptions.currency; + + parts.forEach((p: { type: string; value: any }) => { + if (p.type === 'currency' && currencyCode in INTL_MAPPING) { + const mapping = INTL_MAPPING[currencyCode as keyof typeof INTL_MAPPING]; + if (p.value in mapping) { + p.value = mapping[p.value as keyof typeof mapping]; + } + } + }); + + return parts.map((p) => p.value).join(''); } catch (err) { if (err instanceof Error) { throw new Error(err.message); @@ -29,8 +43,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..1da61bf7 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts @@ -6,7 +6,7 @@ import { } from './types'; import { withErrorBoundary } from '../../common/errorBoundary'; import { getIntlInstanceWithOptions } from '../.internal/utils'; -import { ALLOWED_FORMAT_PARTS_KEYS } from './constants'; +import { ALLOWED_FORMAT_PARTS_KEYS, INTL_MAPPING } from './constants'; const formatNumberByParts = ( amount: string | number, @@ -29,8 +29,17 @@ const formatNumberByParts = ( const parts = formattedAmount; const formattedObj: FormattedPartsObject = {}; + const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; + const currencyCode = options?.currency || intlOptions.currency; parts.forEach((p) => { + if (p.type === 'currency' && currencyCode in INTL_MAPPING) { + const mapping = INTL_MAPPING[currencyCode as keyof typeof INTL_MAPPING]; + if (p.value in mapping) { + p.value = mapping[p.value as keyof typeof mapping]; + } + } + if (p.type === 'group') { formattedObj.integer = (formattedObj.integer || '') + p.value; } else if ( From 2db5acefcaec882c9f99c7409b50717774646c14 Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Thu, 6 Jun 2024 19:09:32 +0530 Subject: [PATCH 02/14] [chore]: add updated i18nify data --- i18nify-data/currency/data.json | 664 +++--------------- .../i18nify-go/modules/currency/data.json | 664 +++--------------- 2 files changed, 210 insertions(+), 1118 deletions(-) diff --git a/i18nify-data/currency/data.json b/i18nify-data/currency/data.json index 625705b4..d9966382 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", @@ -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" - ] + "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" - ] + "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", @@ -546,34 +481,21 @@ "name": "Canadian Dollar", "numeric_code": "124", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "C$", + "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,9 +513,7 @@ "numeric_code": "990", "minor_unit": "4", "symbol": "UF", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "CNY": { "name": "Yuan Renminbi", @@ -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" - ] + "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" - ] + "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", @@ -1333,11 +1108,7 @@ "numeric_code": "422", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "25000", - "50000", - "100000" - ] + "physical_currency_denominations": ["25000", "50000", "100000"] }, "LSL": { "name": "Loti", @@ -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" - ] + "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" - ] + "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" - ] + "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", @@ -2274,9 +1844,7 @@ "numeric_code": "858", "minor_unit": "2", "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "UYU": { "name": "Peso Uruguayo", @@ -2299,9 +1867,7 @@ "numeric_code": "927", "minor_unit": "4", "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "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..d9966382 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", @@ -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" - ] + "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" - ] + "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", @@ -546,34 +481,21 @@ "name": "Canadian Dollar", "numeric_code": "124", "minor_unit": "2", - "symbol": "$", - "physical_currency_denominations": [ - "5", - "10", - "20", - "50", - "100" - ] + "symbol": "C$", + "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,9 +513,7 @@ "numeric_code": "990", "minor_unit": "4", "symbol": "UF", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "CNY": { "name": "Yuan Renminbi", @@ -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" - ] + "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" - ] + "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", @@ -1333,11 +1108,7 @@ "numeric_code": "422", "minor_unit": "2", "symbol": "£", - "physical_currency_denominations": [ - "25000", - "50000", - "100000" - ] + "physical_currency_denominations": ["25000", "50000", "100000"] }, "LSL": { "name": "Loti", @@ -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" - ] + "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" - ] + "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" - ] + "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", @@ -2274,9 +1844,7 @@ "numeric_code": "858", "minor_unit": "2", "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "physical_currency_denominations": ["nan"] }, "UYU": { "name": "Peso Uruguayo", @@ -2299,9 +1867,7 @@ "numeric_code": "927", "minor_unit": "4", "symbol": "nan", - "physical_currency_denominations": [ - "nan" - ] + "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 +} From 66719b895d53e6474c7f9e7a9603c7b9613660da Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Thu, 6 Jun 2024 19:13:42 +0530 Subject: [PATCH 03/14] [chore]: modify INTL_MAPPING to use i18nify-data --- .../src/modules/currency/constants.ts | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/packages/i18nify-js/src/modules/currency/constants.ts b/packages/i18nify-js/src/modules/currency/constants.ts index 00c17ef9..e4b55b5d 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', @@ -22,30 +24,30 @@ export const ALLOWED_FORMAT_PARTS_KEYS = [ // This has been taken from here: https://docs.google.com/spreadsheets/d/13VFVLJql-IPeIV5NTR5MNzeeJp5LVkelbt4jFGUpBlE/edit?usp=sharing export const INTL_MAPPING = { - SGD: { $: 'S$' }, // Singapore Dollar - XCD: { $: 'EC$' }, // East Caribbean Dollar - ARS: { $: 'ARS' }, // Argentine Peso - AUD: { $: 'A$' }, // Australian Dollar - BSD: { $: 'BSD' }, // Bahamian Dollar - BBD: { $: 'Bds$' }, // Barbados Dollar - BMD: { $: 'BD$' }, // Bermudian Dollar - CVE: { $: 'CVE' }, // Cabo Verde Escudo - CAD: { $: 'C$' }, // Canadian Dollar - KYD: { $: 'CI$' }, // Cayman Islands Dollar - CLP: { $: 'CLP' }, // Chilean Peso - COP: { $: 'COL$' }, // Colombian Peso - NZD: { $: 'NZ$' }, // New Zealand Dollar - CUP: { $: '$MN' }, // Cuban Peso - SVC: { $: '₡' }, // El Salvador Colon - FJD: { $: 'FJ$' }, // Fiji Dollar - GYD: { $: 'GY$' }, // Guyana Dollar - HKD: { $: 'HK$' }, // Hong Kong Dollar - JMD: { $: 'J$' }, // Jamaican Dollar - LRD: { $: 'L$' }, // Liberian Dollar - MOP: { $: 'MOP$' }, // Pataca - MXN: { $: 'Mex$' }, // Mexican Peso - NAD: { $: 'N$' }, // Namibia Dollar - SBD: { $: 'SI$' }, // Solomon Islands Dollar - SRD: { $: 'SRD' }, // Surinam Dollar - ZWL: { $: 'Z$' }, // Zimbabwe Dollar + 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 }; From 7294de0b4a54a3424b82a29dd6a0a6242fe99ed4 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Thu, 6 Jun 2024 19:20:37 +0530 Subject: [PATCH 04/14] Create poor-moose-drum.md --- .changeset/poor-moose-drum.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/poor-moose-drum.md 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 From 6c2f12a66cc4ffb68e044bfce27abb4df2740a24 Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Thu, 6 Jun 2024 19:29:10 +0530 Subject: [PATCH 05/14] [chore]: minor changes --- .../src/modules/currency/constants.ts | 1 - .../modules/currency/data/currencyConfig.json | 50 +++++++++---------- .../src/modules/currency/formatNumber.ts | 2 +- .../modules/currency/formatNumberByParts.ts | 2 +- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/packages/i18nify-js/src/modules/currency/constants.ts b/packages/i18nify-js/src/modules/currency/constants.ts index e4b55b5d..95994008 100644 --- a/packages/i18nify-js/src/modules/currency/constants.ts +++ b/packages/i18nify-js/src/modules/currency/constants.ts @@ -22,7 +22,6 @@ export const ALLOWED_FORMAT_PARTS_KEYS = [ 'unit', ] as const; -// This has been taken from here: https://docs.google.com/spreadsheets/d/13VFVLJql-IPeIV5NTR5MNzeeJp5LVkelbt4jFGUpBlE/edit?usp=sharing export const INTL_MAPPING = { SGD: { $: CURRENCY_INFO.SGD.symbol }, // Singapore Dollar XCD: { $: CURRENCY_INFO.XCD.symbol }, // East Caribbean Dollar diff --git a/packages/i18nify-js/src/modules/currency/data/currencyConfig.json b/packages/i18nify-js/src/modules/currency/data/currencyConfig.json index 4c25b3ed..616f81f0 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", @@ -52,7 +52,7 @@ "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,7 +77,7 @@ "BBD": { "name": "Barbados Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "Bds$" }, "BYN": { "name": "Belarusian Ruble", @@ -97,7 +97,7 @@ "BMD": { "name": "Bermudian Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "BD$" }, "INR": { "name": "Indian Rupee", @@ -157,7 +157,7 @@ "CVE": { "name": "Cabo Verde Escudo", "minor_unit": "2", - "symbol": "$" + "symbol": "CVE" }, "KHR": { "name": "Riel", @@ -172,17 +172,17 @@ "CAD": { "name": "Canadian Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "C$" }, "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", @@ -197,7 +197,7 @@ "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", @@ -272,7 +272,7 @@ "SVC": { "name": "El Salvador Colon", "minor_unit": "2", - "symbol": "$" + "symbol": "₡" }, "ERN": { "name": "Nakfa", @@ -297,7 +297,7 @@ "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", @@ -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,7 +512,7 @@ "MXN": { "name": "Mexican Peso", "minor_unit": "2", - "symbol": "$" + "symbol": "Mex$" }, "MXV": { "name": "Mexican Unidad de Inversion (UDI)", @@ -547,7 +547,7 @@ "NAD": { "name": "Namibia Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "N$" }, "NPR": { "name": "Nepalese Rupee", @@ -667,7 +667,7 @@ "SBD": { "name": "Solomon Islands Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "SI$" }, "SOS": { "name": "Somali Shilling", @@ -692,7 +692,7 @@ "SRD": { "name": "Surinam Dollar", "minor_unit": "2", - "symbol": "$" + "symbol": "SRD" }, "SEK": { "name": "Swedish Krona", @@ -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 2c970c45..c86301b4 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumber.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumber.ts @@ -24,7 +24,7 @@ const formatNumber = ( const parts: Array<{ type: string; value: unknown }> = formattedAmount; const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; - const currencyCode = options?.currency || intlOptions.currency; + const currencyCode = options?.currency || intlOptions.currency || 'INR'; parts.forEach((p: { type: string; value: any }) => { if (p.type === 'currency' && currencyCode in INTL_MAPPING) { diff --git a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts index 1da61bf7..8b8b6bc5 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts @@ -30,7 +30,7 @@ const formatNumberByParts = ( const formattedObj: FormattedPartsObject = {}; const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; - const currencyCode = options?.currency || intlOptions.currency; + const currencyCode = options?.currency || intlOptions.currency || 'INR'; parts.forEach((p) => { if (p.type === 'currency' && currencyCode in INTL_MAPPING) { From 9d6e0a8c6bec9987331d6e824db395854beb547d Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Thu, 6 Jun 2024 19:44:10 +0530 Subject: [PATCH 06/14] [fix]: fix type error --- packages/i18nify-js/src/modules/currency/formatNumber.ts | 2 +- packages/i18nify-js/src/modules/currency/formatNumberByParts.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/i18nify-js/src/modules/currency/formatNumber.ts b/packages/i18nify-js/src/modules/currency/formatNumber.ts index c86301b4..60555577 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumber.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumber.ts @@ -24,7 +24,7 @@ const formatNumber = ( const parts: Array<{ type: string; value: unknown }> = formattedAmount; const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; - const currencyCode = options?.currency || intlOptions.currency || 'INR'; + const currencyCode = (options?.currency || intlOptions.currency) as string; parts.forEach((p: { type: string; value: any }) => { if (p.type === 'currency' && currencyCode in INTL_MAPPING) { diff --git a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts index 8b8b6bc5..fd068dc3 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts @@ -30,7 +30,7 @@ const formatNumberByParts = ( const formattedObj: FormattedPartsObject = {}; const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; - const currencyCode = options?.currency || intlOptions.currency || 'INR'; + const currencyCode = (options?.currency || intlOptions.currency) as string; parts.forEach((p) => { if (p.type === 'currency' && currencyCode in INTL_MAPPING) { From 5f1c06d23c65790bd891923076ee8262febeabea Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Fri, 7 Jun 2024 18:14:20 +0530 Subject: [PATCH 07/14] [chore]: update localised currency symbol for other currency codes --- .../src/modules/currency/constants.ts | 10 +++++++ .../modules/currency/data/currencyConfig.json | 30 +++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/i18nify-js/src/modules/currency/constants.ts b/packages/i18nify-js/src/modules/currency/constants.ts index 95994008..e39abf59 100644 --- a/packages/i18nify-js/src/modules/currency/constants.ts +++ b/packages/i18nify-js/src/modules/currency/constants.ts @@ -49,4 +49,14 @@ export const INTL_MAPPING = { 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 616f81f0..9db019f4 100644 --- a/packages/i18nify-js/src/modules/currency/data/currencyConfig.json +++ b/packages/i18nify-js/src/modules/currency/data/currencyConfig.json @@ -47,7 +47,7 @@ "AWG": { "name": "Aruban Florin", "minor_unit": "2", - "symbol": "ƒ" + "symbol": "Aƒ" }, "AUD": { "name": "Australian Dollar", @@ -82,7 +82,7 @@ "BYN": { "name": "Belarusian Ruble", "minor_unit": "2", - "symbol": "Br" + "symbol": "Rbl" }, "BZD": { "name": "Belize Dollar", @@ -117,7 +117,7 @@ "BOV": { "name": "Mvdol", "minor_unit": "2", - "symbol": "nan" + "symbol": "Bs" }, "BAM": { "name": "Convertible Mark", @@ -167,12 +167,12 @@ "XAF": { "name": "CFA Franc BEAC", "minor_unit": "0", - "symbol": "CFA" + "symbol": "FCFA" }, "CAD": { "name": "Canadian Dollar", "minor_unit": "2", - "symbol": "C$" + "symbol": "CA$" }, "KYD": { "name": "Cayman Islands Dollar", @@ -192,7 +192,7 @@ "CNY": { "name": "Yuan Renminbi", "minor_unit": "2", - "symbol": "¥" + "symbol": "CN¥" }, "COP": { "name": "Colombian Peso", @@ -267,7 +267,7 @@ "EGP": { "name": "Egyptian Pound", "minor_unit": "2", - "symbol": "£" + "symbol": "E£" }, "SVC": { "name": "El Salvador Colon", @@ -292,7 +292,7 @@ "FKP": { "name": "Falkland Islands Pound", "minor_unit": "2", - "symbol": "£" + "symbol": "FK£" }, "FJD": { "name": "Fiji Dollar", @@ -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", @@ -517,7 +517,7 @@ "MXV": { "name": "Mexican Unidad de Inversion (UDI)", "minor_unit": "2", - "symbol": "nan" + "symbol": "UDI" }, "MDL": { "name": "Moldovan Leu", @@ -632,7 +632,7 @@ "WST": { "name": "Tala", "minor_unit": "2", - "symbol": "T" + "symbol": "WS$" }, "STN": { "name": "Dobra", @@ -677,7 +677,7 @@ "SSP": { "name": "South Sudanese Pound", "minor_unit": "2", - "symbol": "£" + "symbol": "SS£" }, "LKR": { "name": "Sri Lanka Rupee", @@ -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", From b2b3cec583292274a4569f4536248dca8628b54b Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Fri, 7 Jun 2024 18:21:00 +0530 Subject: [PATCH 08/14] [fix]: fix i18nify-data currency inconsistency --- i18nify-data/currency/data.json | 30 +++++++++---------- .../i18nify-go/modules/currency/data.json | 30 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/i18nify-data/currency/data.json b/i18nify-data/currency/data.json index d9966382..9c50340c 100644 --- a/i18nify-data/currency/data.json +++ b/i18nify-data/currency/data.json @@ -149,7 +149,7 @@ "name": "Aruban Florin", "numeric_code": "533", "minor_unit": "2", - "symbol": "ƒ", + "symbol": "Aƒ", "physical_currency_denominations": [ "5", "10", @@ -228,7 +228,7 @@ "name": "Belarusian Ruble", "numeric_code": "933", "minor_unit": "2", - "symbol": "Br", + "symbol": "Rbl", "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "BZD": { @@ -321,7 +321,7 @@ "name": "Mvdol", "numeric_code": "984", "minor_unit": "2", - "symbol": "nan", + "symbol": "Bs", "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "BAM": { @@ -465,7 +465,7 @@ "name": "CFA Franc BEAC", "numeric_code": "950", "minor_unit": "0", - "symbol": "CFA", + "symbol": "FCFA", "physical_currency_denominations": [ "500", "1000", @@ -481,7 +481,7 @@ "name": "Canadian Dollar", "numeric_code": "124", "minor_unit": "2", - "symbol": "C$", + "symbol": "CA$", "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "KYD": { @@ -519,7 +519,7 @@ "name": "Yuan Renminbi", "numeric_code": "156", "minor_unit": "2", - "symbol": "¥", + "symbol": "CN¥", "physical_currency_denominations": [ "1", "2", @@ -714,7 +714,7 @@ "name": "Egyptian Pound", "numeric_code": "818", "minor_unit": "2", - "symbol": "£", + "symbol": "E£", "physical_currency_denominations": ["25", "50", "100", "200"] }, "SVC": { @@ -761,7 +761,7 @@ "name": "Falkland Islands Pound", "numeric_code": "238", "minor_unit": "2", - "symbol": "£", + "symbol": "FK£", "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "FJD": { @@ -1107,14 +1107,14 @@ "name": "Lebanese Pound", "numeric_code": "422", "minor_unit": "2", - "symbol": "£", + "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", @@ -1287,7 +1287,7 @@ "name": "Mexican Unidad de Inversion (UDI)", "numeric_code": "979", "minor_unit": "2", - "symbol": "nan", + "symbol": "UDI", "physical_currency_denominations": ["nan"] }, "MDL": { @@ -1541,7 +1541,7 @@ "name": "Tala", "numeric_code": "882", "minor_unit": "2", - "symbol": "T", + "symbol": "WS$", "physical_currency_denominations": ["10", "20", "50", "100"] }, "STN": { @@ -1621,7 +1621,7 @@ "name": "South Sudanese Pound", "numeric_code": "728", "minor_unit": "2", - "symbol": "£", + "symbol": "SS£", "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "LKR": { @@ -1843,7 +1843,7 @@ "name": "Uruguay Peso en Unidades Indexadas (URUIURUI)", "numeric_code": "858", "minor_unit": "2", - "symbol": "nan", + "symbol": "$U", "physical_currency_denominations": ["nan"] }, "UYU": { @@ -1866,7 +1866,7 @@ "name": "Unidad Previsional", "numeric_code": "927", "minor_unit": "4", - "symbol": "nan", + "symbol": "UR", "physical_currency_denominations": ["nan"] }, "UZS": { diff --git a/packages/i18nify-go/modules/currency/data.json b/packages/i18nify-go/modules/currency/data.json index d9966382..9c50340c 100644 --- a/packages/i18nify-go/modules/currency/data.json +++ b/packages/i18nify-go/modules/currency/data.json @@ -149,7 +149,7 @@ "name": "Aruban Florin", "numeric_code": "533", "minor_unit": "2", - "symbol": "ƒ", + "symbol": "Aƒ", "physical_currency_denominations": [ "5", "10", @@ -228,7 +228,7 @@ "name": "Belarusian Ruble", "numeric_code": "933", "minor_unit": "2", - "symbol": "Br", + "symbol": "Rbl", "physical_currency_denominations": ["1", "5", "10", "20", "50", "100"] }, "BZD": { @@ -321,7 +321,7 @@ "name": "Mvdol", "numeric_code": "984", "minor_unit": "2", - "symbol": "nan", + "symbol": "Bs", "physical_currency_denominations": ["10", "20", "50", "100", "200"] }, "BAM": { @@ -465,7 +465,7 @@ "name": "CFA Franc BEAC", "numeric_code": "950", "minor_unit": "0", - "symbol": "CFA", + "symbol": "FCFA", "physical_currency_denominations": [ "500", "1000", @@ -481,7 +481,7 @@ "name": "Canadian Dollar", "numeric_code": "124", "minor_unit": "2", - "symbol": "C$", + "symbol": "CA$", "physical_currency_denominations": ["5", "10", "20", "50", "100"] }, "KYD": { @@ -519,7 +519,7 @@ "name": "Yuan Renminbi", "numeric_code": "156", "minor_unit": "2", - "symbol": "¥", + "symbol": "CN¥", "physical_currency_denominations": [ "1", "2", @@ -714,7 +714,7 @@ "name": "Egyptian Pound", "numeric_code": "818", "minor_unit": "2", - "symbol": "£", + "symbol": "E£", "physical_currency_denominations": ["25", "50", "100", "200"] }, "SVC": { @@ -761,7 +761,7 @@ "name": "Falkland Islands Pound", "numeric_code": "238", "minor_unit": "2", - "symbol": "£", + "symbol": "FK£", "physical_currency_denominations": ["1", "2", "5", "10", "20", "50"] }, "FJD": { @@ -1107,14 +1107,14 @@ "name": "Lebanese Pound", "numeric_code": "422", "minor_unit": "2", - "symbol": "£", + "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", @@ -1287,7 +1287,7 @@ "name": "Mexican Unidad de Inversion (UDI)", "numeric_code": "979", "minor_unit": "2", - "symbol": "nan", + "symbol": "UDI", "physical_currency_denominations": ["nan"] }, "MDL": { @@ -1541,7 +1541,7 @@ "name": "Tala", "numeric_code": "882", "minor_unit": "2", - "symbol": "T", + "symbol": "WS$", "physical_currency_denominations": ["10", "20", "50", "100"] }, "STN": { @@ -1621,7 +1621,7 @@ "name": "South Sudanese Pound", "numeric_code": "728", "minor_unit": "2", - "symbol": "£", + "symbol": "SS£", "physical_currency_denominations": ["1", "5", "10", "25", "50", "100"] }, "LKR": { @@ -1843,7 +1843,7 @@ "name": "Uruguay Peso en Unidades Indexadas (URUIURUI)", "numeric_code": "858", "minor_unit": "2", - "symbol": "nan", + "symbol": "$U", "physical_currency_denominations": ["nan"] }, "UYU": { @@ -1866,7 +1866,7 @@ "name": "Unidad Previsional", "numeric_code": "927", "minor_unit": "4", - "symbol": "nan", + "symbol": "UR", "physical_currency_denominations": ["nan"] }, "UZS": { From 5c419392ae15e0db9f7dd3cf9e1a8b94ca80243b Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Fri, 7 Jun 2024 18:40:09 +0530 Subject: [PATCH 09/14] [test]: add missing UTs --- .../currency/__tests__/formatNumber.test.ts | 12 +- .../__tests__/formatNumberByParts.test.ts | 10 + .../__tests__/mocks/formatNumberToParts.ts | 326 +++++++++++++++++- 3 files changed, 343 insertions(+), 5 deletions(-) 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 e3beeee1..5ffe7a2e 100644 --- a/packages/i18nify-js/src/modules/currency/__tests__/formatNumber.test.ts +++ b/packages/i18nify-js/src/modules/currency/__tests__/formatNumber.test.ts @@ -176,7 +176,7 @@ describe('formatNumber', () => { ['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', 'C$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`], @@ -194,6 +194,16 @@ describe('formatNumber', () => { ['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)( 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 43ca3d29..bdbe90a2 100644 --- a/packages/i18nify-js/src/modules/currency/__tests__/formatNumberByParts.test.ts +++ b/packages/i18nify-js/src/modules/currency/__tests__/formatNumberByParts.test.ts @@ -295,6 +295,16 @@ describe('formatNumberByParts', () => { ['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)( diff --git a/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts b/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts index 7780a4e9..c62f445e 100644 --- a/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts +++ b/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts @@ -124,13 +124,13 @@ export const positiveNumberPartsIntlMap = { ], }, CAD: { - currency: 'C$', + currency: 'CA$', decimal: '.', fraction: '33', integer: '123,456', isPrefixSymbol: true, rawParts: [ - { type: 'currency', value: 'C$' }, + { type: 'currency', value: 'CA$' }, { type: 'integer', value: '123' }, { type: 'group', value: ',' }, { type: 'integer', value: '456' }, @@ -396,6 +396,155 @@ export const positiveNumberPartsIntlMap = { { 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' }, + ], + }, }; export const negativeNumberPartsIntlMap = { @@ -538,7 +687,7 @@ export const negativeNumberPartsIntlMap = { ], }, CAD: { - currency: 'C$', + currency: 'CA$', decimal: '.', fraction: '33', integer: '123,456', @@ -546,7 +695,7 @@ export const negativeNumberPartsIntlMap = { minusSign: '-', rawParts: [ { type: 'minusSign', value: '-' }, - { type: 'currency', value: 'C$' }, + { type: 'currency', value: 'CA$' }, { type: 'integer', value: '123' }, { type: 'group', value: ',' }, { type: 'integer', value: '456' }, @@ -846,4 +995,173 @@ export const negativeNumberPartsIntlMap = { { type: 'fraction', value: '33' }, ], }, + LSL: { + currency: 'LSL', + decimal: '.', + fraction: '33', + integer: '123,456', + isPrefixSymbol: true, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { 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, + minusSign: '-', + rawParts: [ + { type: 'minusSign', value: '-' }, + { type: 'currency', value: 'WS$' }, + { type: 'integer', value: '123' }, + { type: 'group', value: ',' }, + { type: 'integer', value: '456' }, + { type: 'decimal', value: '.' }, + { type: 'fraction', value: '33' }, + ], + }, }; From e01cc330f9de258193917f4b7ed3aeb12b552e22 Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Mon, 10 Jun 2024 17:52:45 +0530 Subject: [PATCH 10/14] [chore]: resolve review comments --- .../__tests__/formatNumberByParts.test.ts | 29 +- .../__tests__/mocks/formatNumberToParts.ts | 621 +----------------- .../src/modules/currency/formatNumber.ts | 30 +- .../modules/currency/formatNumberByParts.ts | 17 +- .../i18nify-js/src/modules/currency/types.ts | 1 + 5 files changed, 56 insertions(+), 642 deletions(-) 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 bdbe90a2..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,11 +1,16 @@ import { CurrencyCodeType, formatNumberByParts } from '../index'; -import { - positiveNumberPartsIntlMap, - negativeNumberPartsIntlMap, -} from './mocks/formatNumberToParts'; +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, { @@ -311,27 +316,23 @@ describe('formatNumberByParts', () => { '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( - positiveNumberPartsIntlMap[ - currency as keyof typeof positiveNumberPartsIntlMap - ], - ); + ).toEqual(positiveMock); expect( formatNumberByParts(-amount, { currency: currency as CurrencyCodeType, locale: locale as string, }), - ).toEqual( - negativeNumberPartsIntlMap[ - currency as keyof typeof negativeNumberPartsIntlMap - ], - ); + ).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 index c62f445e..dd0a2e0d 100644 --- a/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts +++ b/packages/i18nify-js/src/modules/currency/__tests__/mocks/formatNumberToParts.ts @@ -1,6 +1,6 @@ const nbsp = String.fromCharCode(160); -export const positiveNumberPartsIntlMap = { +export const numberPartsIntlMap = { SGD: { currency: 'S$', decimal: '.', @@ -546,622 +546,3 @@ export const positiveNumberPartsIntlMap = { ], }, }; - -export const negativeNumberPartsIntlMap = { - SGD: { - currency: 'S$', - decimal: '.', - fraction: '33', - integer: '123,456', - isPrefixSymbol: true, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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, - minusSign: '-', - rawParts: [ - { type: 'minusSign', value: '-' }, - { 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/formatNumber.ts b/packages/i18nify-js/src/modules/currency/formatNumber.ts index 60555577..9c93610c 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumber.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumber.ts @@ -1,6 +1,6 @@ import { withErrorBoundary } from '../../common/errorBoundary'; import { getIntlInstanceWithOptions } from '../.internal/utils'; -import { CurrencyCodeType, I18nifyNumberFormatOptions } from './types'; +import { ByParts, CurrencyCodeType, I18nifyNumberFormatOptions } from './types'; import { INTL_MAPPING } from './constants'; // this function formats number based on different arguments passed @@ -12,31 +12,47 @@ 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}`, ); try { + // Get an instance of Intl.NumberFormat with the provided options const formattedAmount = getIntlInstanceWithOptions(options).formatToParts( Number(amount), ); - const parts: Array<{ type: string; value: unknown }> = formattedAmount; + // Initialize an empty object to store the formatted parts + const parts: ByParts['rawParts'] = formattedAmount; const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; const currencyCode = (options?.currency || intlOptions.currency) as string; - parts.forEach((p: { type: string; value: any }) => { - if (p.type === 'currency' && currencyCode in INTL_MAPPING) { + // Loop through each part of the formatted amount + for (let i = 0; i < parts.length; i++) { + const part = parts[i]; + /** If the part is of type 'currency' and the provided currency code exists in INTL_MAPPING, + * replace the value of this part with the corresponding value from INTL_MAPPING. + * This replacement is done to allow customization of the currency symbol or other parameters, + * which may differ from the defaults provided by the Intl API. + * + * Example: If the original currency symbol provided by Intl API is '$', but for the + * currency code 'SGD', we want to use 'S$', then we use INTL_MAPPING to make this replacement. + */ + if (part.type === 'currency' && currencyCode in INTL_MAPPING) { const mapping = INTL_MAPPING[currencyCode as keyof typeof INTL_MAPPING]; - if (p.value in mapping) { - p.value = mapping[p.value as keyof typeof 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 } } - }); + } + // Join the parts back together to form the final formatted string return parts.map((p) => p.value).join(''); } catch (err) { + // Handle errors by throwing a new Error with the error message if (err instanceof Error) { throw new Error(err.message); } else { diff --git a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts index fd068dc3..5fb4c673 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts @@ -16,23 +16,34 @@ 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), ); + // Initialize an empty object to store the formatted parts const parts = formattedAmount; - const formattedObj: FormattedPartsObject = {}; const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; const currencyCode = (options?.currency || intlOptions.currency) as string; + // Loop through each part of the formatted amount parts.forEach((p) => { + /** If the part is of type 'currency' and the provided currency code exists in INTL_MAPPING, + * replace the value of this part with the corresponding value from INTL_MAPPING. + * This replacement is done to allow customization of the currency symbol or other parameters, + * which may differ from the defaults provided by the Intl API. + * + * Example: If the original currency symbol provided by Intl API is '$', but for the + * currency code 'SGD', we want to use 'S$', then we use INTL_MAPPING to make this replacement. + */ if (p.type === 'currency' && currencyCode in INTL_MAPPING) { const mapping = INTL_MAPPING[currencyCode as keyof typeof INTL_MAPPING]; if (p.value in mapping) { @@ -40,16 +51,19 @@ const formatNumberByParts = ( } } + // 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; } }); + // Determine if the currency symbol is a prefix return { ...formattedObj, isPrefixSymbol: @@ -58,6 +72,7 @@ const formatNumberByParts = ( rawParts: parts, }; } catch (err) { + // Handle errors by throwing a new Error with the error message if (err instanceof Error) { throw new Error(err.message); } else { 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 }>; From 2be1580719180571be479b52f49be3632de3b8ac Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Tue, 11 Jun 2024 01:35:30 +0530 Subject: [PATCH 11/14] [chore]: resolve review comments --- .../src/modules/currency/formatNumber.ts | 24 ++----------- .../modules/currency/formatNumberByParts.ts | 22 +++--------- .../i18nify-js/src/modules/currency/utils.ts | 35 +++++++++++++++++++ 3 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 packages/i18nify-js/src/modules/currency/utils.ts diff --git a/packages/i18nify-js/src/modules/currency/formatNumber.ts b/packages/i18nify-js/src/modules/currency/formatNumber.ts index 9c93610c..c586d4be 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumber.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumber.ts @@ -1,7 +1,7 @@ import { withErrorBoundary } from '../../common/errorBoundary'; import { getIntlInstanceWithOptions } from '../.internal/utils'; import { ByParts, CurrencyCodeType, I18nifyNumberFormatOptions } from './types'; -import { INTL_MAPPING } from './constants'; +import { configureIntlFromI18nifyData } from './utils'; // this function formats number based on different arguments passed const formatNumber = ( @@ -25,29 +25,11 @@ const formatNumber = ( ); // Initialize an empty object to store the formatted parts - const parts: ByParts['rawParts'] = formattedAmount; + let parts: ByParts['rawParts'] = formattedAmount; const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; const currencyCode = (options?.currency || intlOptions.currency) as string; - // Loop through each part of the formatted amount - for (let i = 0; i < parts.length; i++) { - const part = parts[i]; - /** If the part is of type 'currency' and the provided currency code exists in INTL_MAPPING, - * replace the value of this part with the corresponding value from INTL_MAPPING. - * This replacement is done to allow customization of the currency symbol or other parameters, - * which may differ from the defaults provided by the Intl API. - * - * Example: If the original currency symbol provided by Intl API is '$', but for the - * currency code 'SGD', we want to use 'S$', then we use INTL_MAPPING to make this replacement. - */ - 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 - } - } - } + parts = configureIntlFromI18nifyData(parts, currencyCode); // Join the parts back together to form the final formatted string return parts.map((p) => p.value).join(''); diff --git a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts index 5fb4c673..0a81330b 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts @@ -6,7 +6,8 @@ import { } from './types'; import { withErrorBoundary } from '../../common/errorBoundary'; import { getIntlInstanceWithOptions } from '../.internal/utils'; -import { ALLOWED_FORMAT_PARTS_KEYS, INTL_MAPPING } from './constants'; +import { ALLOWED_FORMAT_PARTS_KEYS } from './constants'; +import { configureIntlFromI18nifyData } from './utils'; const formatNumberByParts = ( amount: string | number, @@ -29,28 +30,15 @@ const formatNumberByParts = ( ); // Initialize an empty object to store the formatted parts - 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 = configureIntlFromI18nifyData(parts, currencyCode); + // Loop through each part of the formatted amount parts.forEach((p) => { - /** If the part is of type 'currency' and the provided currency code exists in INTL_MAPPING, - * replace the value of this part with the corresponding value from INTL_MAPPING. - * This replacement is done to allow customization of the currency symbol or other parameters, - * which may differ from the defaults provided by the Intl API. - * - * Example: If the original currency symbol provided by Intl API is '$', but for the - * currency code 'SGD', we want to use 'S$', then we use INTL_MAPPING to make this replacement. - */ - if (p.type === 'currency' && currencyCode in INTL_MAPPING) { - const mapping = INTL_MAPPING[currencyCode as keyof typeof INTL_MAPPING]; - if (p.value in mapping) { - p.value = mapping[p.value as keyof typeof mapping]; - } - } - // If the part is a group separator, add it to the integer part if (p.type === 'group') { formattedObj.integer = (formattedObj.integer || '') + p.value; 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..c7b1aa5a --- /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 configureIntlFromI18nifyData = ( + 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; +}; From 60d9d3c194cc7acfc8b82a128601a758c0653e1d Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Tue, 11 Jun 2024 02:04:52 +0530 Subject: [PATCH 12/14] [chore]: resolve review comments --- .../configureIntlFromI18nifyData.test.ts | 46 +++++++++++++++++++ .../mocks/configureIntlFromI18nifyData.ts | 8 ++++ 2 files changed, 54 insertions(+) create mode 100644 packages/i18nify-js/src/modules/currency/__tests__/configureIntlFromI18nifyData.test.ts create mode 100644 packages/i18nify-js/src/modules/currency/__tests__/mocks/configureIntlFromI18nifyData.ts diff --git a/packages/i18nify-js/src/modules/currency/__tests__/configureIntlFromI18nifyData.test.ts b/packages/i18nify-js/src/modules/currency/__tests__/configureIntlFromI18nifyData.test.ts new file mode 100644 index 00000000..8ba673db --- /dev/null +++ b/packages/i18nify-js/src/modules/currency/__tests__/configureIntlFromI18nifyData.test.ts @@ -0,0 +1,46 @@ +import { INTL_MAPPING } from '../constants'; +import { ByParts } from '../types'; +import { configureIntlFromI18nifyData } from '../utils'; +import { getMockParts } from './mocks/configureIntlFromI18nifyData'; + +describe('configureIntlFromI18nifyData', () => { + 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 = configureIntlFromI18nifyData(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 = configureIntlFromI18nifyData(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 = configureIntlFromI18nifyData( + mockPartsWithDifferentCurrencySymbol, + currencyCode, + ); + expect(result).toEqual(mockPartsWithDifferentCurrencySymbol); + }); +}); diff --git a/packages/i18nify-js/src/modules/currency/__tests__/mocks/configureIntlFromI18nifyData.ts b/packages/i18nify-js/src/modules/currency/__tests__/mocks/configureIntlFromI18nifyData.ts new file mode 100644 index 00000000..c302142e --- /dev/null +++ b/packages/i18nify-js/src/modules/currency/__tests__/mocks/configureIntlFromI18nifyData.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' }, +]; From 2b6603178a55168cd0b7a270c847bacfb71a0ca4 Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Tue, 11 Jun 2024 02:11:06 +0530 Subject: [PATCH 13/14] [chore]: resolve review comments --- packages/i18nify-js/src/modules/currency/formatNumber.ts | 2 -- .../i18nify-js/src/modules/currency/formatNumberByParts.ts | 4 ---- 2 files changed, 6 deletions(-) diff --git a/packages/i18nify-js/src/modules/currency/formatNumber.ts b/packages/i18nify-js/src/modules/currency/formatNumber.ts index c586d4be..1469b650 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumber.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumber.ts @@ -24,7 +24,6 @@ const formatNumber = ( Number(amount), ); - // Initialize an empty object to store the formatted parts let parts: ByParts['rawParts'] = formattedAmount; const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; const currencyCode = (options?.currency || intlOptions.currency) as string; @@ -34,7 +33,6 @@ const formatNumber = ( // Join the parts back together to form the final formatted string return parts.map((p) => p.value).join(''); } catch (err) { - // Handle errors by throwing a new Error with the error message if (err instanceof Error) { throw new Error(err.message); } else { diff --git a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts index 0a81330b..6cd378cd 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts @@ -29,7 +29,6 @@ const formatNumberByParts = ( Number(amount), ); - // Initialize an empty object to store the formatted parts let parts: ByParts['rawParts'] = formattedAmount; const formattedObj: FormattedPartsObject = {}; const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; @@ -37,7 +36,6 @@ const formatNumberByParts = ( parts = configureIntlFromI18nifyData(parts, currencyCode); - // Loop through each part of the formatted amount parts.forEach((p) => { // If the part is a group separator, add it to the integer part if (p.type === 'group') { @@ -51,7 +49,6 @@ const formatNumberByParts = ( } }); - // Determine if the currency symbol is a prefix return { ...formattedObj, isPrefixSymbol: @@ -60,7 +57,6 @@ const formatNumberByParts = ( rawParts: parts, }; } catch (err) { - // Handle errors by throwing a new Error with the error message if (err instanceof Error) { throw new Error(err.message); } else { From 3cd696e0e7762823be938aafb0b1d17f4bf7ec01 Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Tue, 11 Jun 2024 10:21:07 +0530 Subject: [PATCH 14/14] [chore]: resolve review comments --- ...lFromI18nifyData.ts => transformPartsFromIntl.ts} | 0 ...fyData.test.ts => transformPartsFromIntl.test.ts} | 12 ++++++------ .../i18nify-js/src/modules/currency/formatNumber.ts | 4 ++-- .../src/modules/currency/formatNumberByParts.ts | 4 ++-- packages/i18nify-js/src/modules/currency/utils.ts | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) rename packages/i18nify-js/src/modules/currency/__tests__/mocks/{configureIntlFromI18nifyData.ts => transformPartsFromIntl.ts} (100%) rename packages/i18nify-js/src/modules/currency/__tests__/{configureIntlFromI18nifyData.test.ts => transformPartsFromIntl.test.ts} (79%) diff --git a/packages/i18nify-js/src/modules/currency/__tests__/mocks/configureIntlFromI18nifyData.ts b/packages/i18nify-js/src/modules/currency/__tests__/mocks/transformPartsFromIntl.ts similarity index 100% rename from packages/i18nify-js/src/modules/currency/__tests__/mocks/configureIntlFromI18nifyData.ts rename to packages/i18nify-js/src/modules/currency/__tests__/mocks/transformPartsFromIntl.ts diff --git a/packages/i18nify-js/src/modules/currency/__tests__/configureIntlFromI18nifyData.test.ts b/packages/i18nify-js/src/modules/currency/__tests__/transformPartsFromIntl.test.ts similarity index 79% rename from packages/i18nify-js/src/modules/currency/__tests__/configureIntlFromI18nifyData.test.ts rename to packages/i18nify-js/src/modules/currency/__tests__/transformPartsFromIntl.test.ts index 8ba673db..720011af 100644 --- a/packages/i18nify-js/src/modules/currency/__tests__/configureIntlFromI18nifyData.test.ts +++ b/packages/i18nify-js/src/modules/currency/__tests__/transformPartsFromIntl.test.ts @@ -1,9 +1,9 @@ import { INTL_MAPPING } from '../constants'; import { ByParts } from '../types'; -import { configureIntlFromI18nifyData } from '../utils'; -import { getMockParts } from './mocks/configureIntlFromI18nifyData'; +import { transformPartsFromIntl } from '../utils'; +import { getMockParts } from './mocks/transformPartsFromIntl'; -describe('configureIntlFromI18nifyData', () => { +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; @@ -16,7 +16,7 @@ describe('configureIntlFromI18nifyData', () => { ]; it(`should replace the currency symbol with the value from INTL_MAPPING for ${currencyCode}`, () => { - const result = configureIntlFromI18nifyData(mockParts, currencyCode); + const result = transformPartsFromIntl(mockParts, currencyCode); expect(result).toEqual(expectedParts); }); }); @@ -24,7 +24,7 @@ describe('configureIntlFromI18nifyData', () => { it('should not modify parts if currency code is not in INTL_MAPPING', () => { const currencyCode = 'XYZ'; const mockParts = getMockParts('$'); - const result = configureIntlFromI18nifyData(mockParts, currencyCode); + const result = transformPartsFromIntl(mockParts, currencyCode); expect(result).toEqual(mockParts); }); @@ -37,7 +37,7 @@ describe('configureIntlFromI18nifyData', () => { ]; const currencyCode = 'SGD'; - const result = configureIntlFromI18nifyData( + const result = transformPartsFromIntl( mockPartsWithDifferentCurrencySymbol, currencyCode, ); diff --git a/packages/i18nify-js/src/modules/currency/formatNumber.ts b/packages/i18nify-js/src/modules/currency/formatNumber.ts index 1469b650..8fb38c3e 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumber.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumber.ts @@ -1,7 +1,7 @@ import { withErrorBoundary } from '../../common/errorBoundary'; import { getIntlInstanceWithOptions } from '../.internal/utils'; import { ByParts, CurrencyCodeType, I18nifyNumberFormatOptions } from './types'; -import { configureIntlFromI18nifyData } from './utils'; +import { transformPartsFromIntl } from './utils'; // this function formats number based on different arguments passed const formatNumber = ( @@ -28,7 +28,7 @@ const formatNumber = ( const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; const currencyCode = (options?.currency || intlOptions.currency) as string; - parts = configureIntlFromI18nifyData(parts, currencyCode); + parts = transformPartsFromIntl(parts, currencyCode); // Join the parts back together to form the final formatted string return parts.map((p) => p.value).join(''); diff --git a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts index 6cd378cd..02e7f6ab 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts @@ -7,7 +7,7 @@ import { import { withErrorBoundary } from '../../common/errorBoundary'; import { getIntlInstanceWithOptions } from '../.internal/utils'; import { ALLOWED_FORMAT_PARTS_KEYS } from './constants'; -import { configureIntlFromI18nifyData } from './utils'; +import { transformPartsFromIntl } from './utils'; const formatNumberByParts = ( amount: string | number, @@ -34,7 +34,7 @@ const formatNumberByParts = ( const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {}; const currencyCode = (options?.currency || intlOptions.currency) as string; - parts = configureIntlFromI18nifyData(parts, currencyCode); + parts = transformPartsFromIntl(parts, currencyCode); parts.forEach((p) => { // If the part is a group separator, add it to the integer part diff --git a/packages/i18nify-js/src/modules/currency/utils.ts b/packages/i18nify-js/src/modules/currency/utils.ts index c7b1aa5a..72f153da 100644 --- a/packages/i18nify-js/src/modules/currency/utils.ts +++ b/packages/i18nify-js/src/modules/currency/utils.ts @@ -14,7 +14,7 @@ import { ByParts } from './types'; * @returns {ByParts['rawParts']} - The modified array of parts with replaced values based on the * local i18nify configuration. */ -export const configureIntlFromI18nifyData = ( +export const transformPartsFromIntl = ( parts: ByParts['rawParts'], currencyCode: string, ): ByParts['rawParts'] => {