From c870c79f4013538f1f4c54327d8f44ded52d7fc6 Mon Sep 17 00:00:00 2001 From: -l Date: Tue, 29 Oct 2024 15:52:01 +0100 Subject: [PATCH 1/3] fix(NumberFormat): not break code when not providing a currency --- .../dnb-eufemia/src/components/number-format/NumberUtils.js | 2 +- .../components/number-format/__tests__/NumberUtils.test.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/dnb-eufemia/src/components/number-format/NumberUtils.js b/packages/dnb-eufemia/src/components/number-format/NumberUtils.js index 2bab75c1259..bab65c906dc 100644 --- a/packages/dnb-eufemia/src/components/number-format/NumberUtils.js +++ b/packages/dnb-eufemia/src/components/number-format/NumberUtils.js @@ -486,7 +486,7 @@ const prepareMinus = (display, locale) => { * @returns {string} The aligned output string. */ function alignCurrencySymbol(output, currencyDisplay) { - if (currencyDisplay === 'name') { + if (output && currencyDisplay === 'name') { output = output.replace(/(nor[^\s]+?)\s(\w+)/i, '$2') } return output diff --git a/packages/dnb-eufemia/src/components/number-format/__tests__/NumberUtils.test.ts b/packages/dnb-eufemia/src/components/number-format/__tests__/NumberUtils.test.ts index 59768562039..163ba1326e2 100644 --- a/packages/dnb-eufemia/src/components/number-format/__tests__/NumberUtils.test.ts +++ b/packages/dnb-eufemia/src/components/number-format/__tests__/NumberUtils.test.ts @@ -109,6 +109,11 @@ describe('Decimals format', () => { decimals: undefined, }) ).toBe('-1,1234567891234568') + + expect(format(null, { currency: 'non-valid value' })).toBe('null') + expect(format(undefined, { currency: 'non-valid value' })).toBe( + 'undefined' + ) }) describe('rounding', () => { From 2dece3d0984009531e95a557f2ca740544b07adf Mon Sep 17 00:00:00 2001 From: Anders Date: Tue, 29 Oct 2024 16:22:35 +0100 Subject: [PATCH 2/3] Update NumberUtils.test.ts --- .../src/components/number-format/__tests__/NumberUtils.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/dnb-eufemia/src/components/number-format/__tests__/NumberUtils.test.ts b/packages/dnb-eufemia/src/components/number-format/__tests__/NumberUtils.test.ts index 163ba1326e2..2f7d2e3b008 100644 --- a/packages/dnb-eufemia/src/components/number-format/__tests__/NumberUtils.test.ts +++ b/packages/dnb-eufemia/src/components/number-format/__tests__/NumberUtils.test.ts @@ -109,7 +109,6 @@ describe('Decimals format', () => { decimals: undefined, }) ).toBe('-1,1234567891234568') - expect(format(null, { currency: 'non-valid value' })).toBe('null') expect(format(undefined, { currency: 'non-valid value' })).toBe( 'undefined' From 395019bc01a02ae83ad90676d67745cd4600145c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B8egh?= Date: Tue, 29 Oct 2024 16:23:32 +0100 Subject: [PATCH 3/3] Update NumberUtils.js --- .../dnb-eufemia/src/components/number-format/NumberUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dnb-eufemia/src/components/number-format/NumberUtils.js b/packages/dnb-eufemia/src/components/number-format/NumberUtils.js index bab65c906dc..9dab14611db 100644 --- a/packages/dnb-eufemia/src/components/number-format/NumberUtils.js +++ b/packages/dnb-eufemia/src/components/number-format/NumberUtils.js @@ -486,7 +486,7 @@ const prepareMinus = (display, locale) => { * @returns {string} The aligned output string. */ function alignCurrencySymbol(output, currencyDisplay) { - if (output && currencyDisplay === 'name') { + if (typeof output === 'string' && currencyDisplay === 'name') { output = output.replace(/(nor[^\s]+?)\s(\w+)/i, '$2') } return output