Skip to content

Commit

Permalink
feat(@formatjs/intl-getcanonicallocales): expose polyfill-force varia…
Browse files Browse the repository at this point in the history
…nt (#3997)
  • Loading branch information
arthurdenner committed Feb 20, 2023
1 parent 31561be commit d513ce6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/intl-getcanonicallocales/polyfill-force.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {getCanonicalLocales} from './'
if (typeof Intl === 'undefined') {
if (typeof window !== 'undefined') {
Object.defineProperty(window, 'Intl', {
value: {},
})
// @ts-ignore we don't include @types/node so global isn't a thing
} else if (typeof global !== 'undefined') {
// @ts-ignore we don't include @types/node so global isn't a thing
Object.defineProperty(global, 'Intl', {
value: {},
})
}
}
Object.defineProperty(Intl, 'getCanonicalLocales', {
value: getCanonicalLocales,
writable: true,
enumerable: false,
configurable: true,
})
2 changes: 2 additions & 0 deletions website/docs/polyfills/intl-getcanonicallocales.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ async function polyfill() {
if (shouldPolyfill()) {
await import('@formatjs/intl-getcanonicallocales/polyfill')
}
// Alternatively, force the polyfill regardless of support
await import('@formatjs/intl-getcanonicallocales/polyfill-force')
}
```

Expand Down

0 comments on commit d513ce6

Please sign in to comment.