UNPKG

831 BPlain TextView Raw
1/*
2 * Copyright 2015, Yahoo Inc.
3 * Copyrights licensed under the New BSD License.
4 * See the accompanying LICENSE file for terms.
5 */
6const DEFAULT_CONSTRUCTORS = [
7 Intl.DateTimeFormat,
8 Intl.NumberFormat,
9 Intl.PluralRules
10];
11export default function areIntlLocalesSupported(
12 locales: string | string[],
13 constructorsToCheck = DEFAULT_CONSTRUCTORS
14): boolean {
15 if (typeof Intl === 'undefined') {
16 return false;
17 }
18
19 if (!locales) {
20 throw new Error('locales must be supplied.');
21 }
22
23 if (!Array.isArray(locales)) {
24 locales = [locales];
25 }
26
27 const intlConstructors = constructorsToCheck.filter(Boolean);
28
29 if (intlConstructors.length === 0) {
30 return false;
31 }
32
33 return intlConstructors.every(
34 intlConstructor =>
35 intlConstructor.supportedLocalesOf(locales).length === locales.length
36 );
37}