Skip to content

Commit

Permalink
Merge 64b5ea1 into ac7659a
Browse files Browse the repository at this point in the history
  • Loading branch information
flepretre committed May 6, 2019
2 parents ac7659a + 64b5ea1 commit 770124b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "10"
- "11"

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.13.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Currency utils should format in 'en' currency 1`] = `"$100,000.00"`;

exports[`Currency utils should format in 'fr' currency 1`] = `"100 000,00 €"`;

exports[`Currency utils should format in 'hr' currency 1`] = `"100.000,00 HRK"`;

exports[`Currency utils should format in 'hu' currency 1`] = `"100 000,00 Ft"`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { currencyFunctions } from '../currency.utils';

describe('Currency utils', () => {
['fr', 'en', 'hu', 'hr'].forEach(locale => {
it(`should format in '${locale}' currency`, () => {
expect(currencyFunctions[locale](100000)).toMatchSnapshot();
});
});
});
8 changes: 8 additions & 0 deletions packages/react-i18n/src/utils/currency.utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const currencyBuilder = (locale, currency) => new Intl.NumberFormat(locale, { style: 'currency', currency }).format;

export const currencyFunctions = {
fr: currencyBuilder('fr-FR', 'EUR'),
en: currencyBuilder('us-EN', 'USD'),
hu: currencyBuilder('hu-HU', 'HUF'),
hr: currencyBuilder('hr-HR', 'HRK'),
};

0 comments on commit 770124b

Please sign in to comment.