Skip to content

Commit

Permalink
feat(@formatjs/intl-displaynames): add supported locales check to sho…
Browse files Browse the repository at this point in the history
…uld-polyfill, fix #3066
  • Loading branch information
longlho committed Jul 24, 2021
1 parent 59d297e commit 4d39f5c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/intl-displaynames/should-polyfill.ts
Expand Up @@ -28,6 +28,22 @@ function hasScriptBug() {
return false
}

export function shouldPolyfill() {
return !(Intl as any).DisplayNames || hasMissingICUBug() || hasScriptBug()
function supportedLocalesOf(locale?: string | string[]) {
if (!locale) {
return true
}
const locales = Array.isArray(locale) ? locale : [locale]
return (
(Intl as any).DisplayNames.supportedLocalesOf(locales).length ===
locales.length
)
}

export function shouldPolyfill(locale?: string | string[]) {
return (
!(Intl as any).DisplayNames ||
hasMissingICUBug() ||
hasScriptBug() ||
!supportedLocalesOf(locale)
)
}

0 comments on commit 4d39f5c

Please sign in to comment.