Skip to content

Commit

Permalink
fix: ensure that NumberFormat.formatToParts is available (#5)
Browse files Browse the repository at this point in the history
* chore: upgrade deps

* fix: ensure that NumberFormat.formatToParts is available

IE 11 and Edge < 18 support `Intl.NumberFormat`, but not the `Intl.NumberFormat.formatToParts` API.

* chore: rename master branch to main
  • Loading branch information
connor-baer authored Jul 21, 2020
1 parent ebbad42 commit bf466fd
Show file tree
Hide file tree
Showing 6 changed files with 993 additions and 1,079 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ If you feel another member of the community violated our CoC or you are experien
### Submitting a PR

1. Find an existing issue to work on or follow `Submitting an issue` to create one that you're also going to fix. Make sure to notify that you're working on a fix for the issue you picked.
2. Branch out from latest `master`.
2. Branch out from latest `main`.
3. Code, add, commit and push your changes in your branch.
4. Make sure that tests and linter(s) pass locally for you.
5. Submit a PR.
6. Collaborate with the codeowners/reviewers to merge this in `master`.
6. Collaborate with the codeowners/reviewers to merge this in `main`.

## Common commands

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Intl.js

[![Coverage](https://img.shields.io/codecov/c/github/sumup-oss/intl-js)](https://codecov.io/gh/sumup-oss/intl-js) [![License](https://img.shields.io/github/license/sumup-oss/intl-js)](https://github.com/sumup-oss/intl-js/blob/master/LICENSE)
[![Coverage](https://img.shields.io/codecov/c/github/sumup-oss/intl-js)](https://codecov.io/gh/sumup-oss/intl-js) [![License](https://img.shields.io/github/license/sumup-oss/intl-js)](https://github.com/sumup-oss/intl-js/blob/main/LICENSE)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)

Format 🔢 numbers and 💱currency values for any locale with the [ECMAScript Internationalization API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl).
Expand Down Expand Up @@ -324,7 +324,7 @@ const isIntlSupported: boolean;

#### `CURRENCIES`

An object that maps a 2 char country code to its official 3 char currency code. [View all supported countries](https://github.com/sumup-oss/intl-js/blob/master/src/data/currencies.ts).
An object that maps a 2 char country code to its official 3 char currency code. [View all supported countries](https://github.com/sumup-oss/intl-js/blob/main/src/data/currencies.ts).

```ts
const CURRENCIES: { [country: string]: string };
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
"intl-format-cache": "^4.2.27"
},
"devDependencies": {
"@sumup/foundry": "^2.2.0",
"@sumup/foundry": "^3.0.0",
"@types/jest": "^25.2.0",
"audit-ci": "^3.0.0",
"jest": "^26.0.0",
"jest-extended": "^0.11.4",
"jest-junit": "^10.0.0",
"license-checker": "^25.0.1",
"ts-jest": "^25.0.0",
"ts-jest": "^26.0.0",
"typescript": "^3.7.5"
}
}
5 changes: 4 additions & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export function formatToPartsFactory<T extends Args>(
locales?: Locale | Locale[],
...args: T
): Intl.NumberFormatPart[] => {
if (!isIntlSupported) {
if (
!isIntlSupported ||
typeof Intl.NumberFormat.prototype.formatToParts === 'undefined'
) {
return [{ type: 'integer', value: value.toString() }];
}

Expand Down
2 changes: 1 addition & 1 deletion src/data/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Currency } from '../types';

/**
* An object that maps a 2 char country code to its official 3 char currency code.
* [View all supported countries](https://github.com/sumup-oss/intl-js/blob/master/src/data/currencies.ts).
* [View all supported countries](https://github.com/sumup-oss/intl-js/blob/main/src/data/currencies.ts).
*/
export const CURRENCIES: { [country: string]: Currency } = {
// Andorra
Expand Down
Loading

0 comments on commit bf466fd

Please sign in to comment.