From bed15fdf738b5db1da46f67e6fd96da01ce11229 Mon Sep 17 00:00:00 2001 From: Jenny Hoac Date: Mon, 29 Jan 2018 16:45:24 -0500 Subject: [PATCH 1/2] Adding case for formatting None currency --- src/lib/formats.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/formats.ts b/src/lib/formats.ts index 11b5e9c..9409b43 100644 --- a/src/lib/formats.ts +++ b/src/lib/formats.ts @@ -55,6 +55,9 @@ export class Formats { let _format: Intl.NumberFormatOptions = (typeof format === 'string') ? mergeDeep({}, { currency: format }, this.defaults.currency) : mergeDeep({}, format, this.defaults.currency); let options = mergeDeep({ style: 'currency', currency: 'USD' }, _format); if (this.overrideCurrency) { + if (this.overrideCurrency === 'None') { + return new Intl.NumberFormat([this.locale, 'en-US'], {minimumFractionDigits: 2, maximumFractionDigits: 2}).format(value); + } options.currency = this.overrideCurrency; } From 52d9d89e8c6f9808ae2adee47d4f0a54af783190 Mon Sep 17 00:00:00 2001 From: Jenny Hoac Date: Mon, 29 Jan 2018 17:19:01 -0500 Subject: [PATCH 2/2] Adding test case for overrideCurrency of None --- src/lib/currency-overrides.ts | 2 +- src/lib/formats.spec.ts | 6 ++++++ src/lib/formats.ts | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/currency-overrides.ts b/src/lib/currency-overrides.ts index 2f1dbd5..eab35b2 100644 --- a/src/lib/currency-overrides.ts +++ b/src/lib/currency-overrides.ts @@ -6,4 +6,4 @@ export const currencyOverridesMap = { SEK: 'kr', NOK: 'kr', ZAR: 'R' -}; \ No newline at end of file +}; diff --git a/src/lib/formats.spec.ts b/src/lib/formats.spec.ts index 83dfd5c..f4a02ef 100644 --- a/src/lib/formats.spec.ts +++ b/src/lib/formats.spec.ts @@ -202,6 +202,12 @@ test('currency should use the override currency if set', t => { t.is(t.context.formats.formatCurrency(123456.789), 'RUB123,456.79'); }); +test('currency should be able to format with currency format of None', t => { + t.context.formats.setLocale('en-US'); + t.context.formats.overrideCurrency = 'None'; + t.is(t.context.formats.formatCurrency(123456.789), '123,456.79'); +}); + // formatDate(value, format) test('formatDate should default to en-US for unknown locale', t => { diff --git a/src/lib/formats.ts b/src/lib/formats.ts index 9409b43..3ce7591 100644 --- a/src/lib/formats.ts +++ b/src/lib/formats.ts @@ -1,5 +1,5 @@ import { mergeDeep } from './object-assign-deep'; -import { currencyOverridesMap } from './currency-overrides' +import { currencyOverridesMap } from './currency-overrides'; // Interface for defaults export interface IFormatDefaults {