Skip to content

Commit

Permalink
feat(@formatjs/intl-locale): expose shouldPolyfill to detect if platf…
Browse files Browse the repository at this point in the history
…orm needs our polyfill
  • Loading branch information
longlho committed Aug 18, 2020
1 parent 7f62ccd commit 3ed62e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/intl-locale/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Locale} from './';
if (!('Locale' in Intl)) {
import {shouldPolyfill} from './should-polyfill';
if (shouldPolyfill()) {
Object.defineProperty(Intl, 'Locale', {
value: Locale,
writable: true,
Expand Down
8 changes: 8 additions & 0 deletions packages/intl-locale/should-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function shouldPolyfill() {
return (
typeof Intl === 'undefined' ||
!('Locale' in Intl) ||
// https://bugs.chromium.org/p/v8/issues/detail?id=10682
new (Intl as any).Locale('und-x-private').toString() === 'x-private'
);
}

0 comments on commit 3ed62e2

Please sign in to comment.