@formatjs/intl-listformat 8.3.13 → 8.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -31,7 +31,7 @@ interface LiteralPart {
31
31
  }
32
32
  //#endregion
33
33
  //#region packages/intl-listformat/index.d.ts
34
- interface IntlListFormatOptions {
34
+ export interface IntlListFormatOptions {
35
35
  /**
36
36
  * The locale matching algorithm to use.
37
37
  * Possible values are "lookup" and "best fit"; the default is "best fit".
@@ -57,7 +57,7 @@ interface IntlListFormatOptions {
57
57
  */
58
58
  style?: "long" | "short" | "narrow";
59
59
  }
60
- interface ResolvedIntlListFormatOptions {
60
+ export interface ResolvedIntlListFormatOptions {
61
61
  /**
62
62
  * A string with a BCP 47 language tag, or an array of such strings.
63
63
  * For the general form and interpretation of the locales argument,
@@ -82,12 +82,12 @@ interface ResolvedIntlListFormatOptions {
82
82
  */
83
83
  style: "long" | "short" | "narrow";
84
84
  }
85
- type Part<T = string> = LiteralPart | ElementPart | ElementPart<T>;
86
- interface ElementPart<T = string> {
85
+ export type Part<T = string> = LiteralPart | ElementPart | ElementPart<T>;
86
+ export interface ElementPart<T = string> {
87
87
  type: "element";
88
88
  value: T;
89
89
  }
90
- declare class ListFormat {
90
+ export default class ListFormat {
91
91
  constructor(locales?: string | string[], options?: IntlListFormatOptions);
92
92
  format(elements: Iterable<string>): string;
93
93
  formatToParts(elements: Iterable<string>): Part[];
@@ -103,5 +103,4 @@ declare class ListFormat {
103
103
  private static readonly __INTERNAL_SLOT_MAP__;
104
104
  }
105
105
  //#endregion
106
- export { ElementPart, IntlListFormatOptions, Part, ResolvedIntlListFormatOptions, ListFormat as default };
107
106
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,4 +1,392 @@
1
1
  import { LookupSupportedLocales, ResolveLocale } from "@formatjs/intl-localematcher";
2
+ //#region node_modules/.aspect_rules_js/@formatjs_generated+cldr.supported-locales@0.0.0/node_modules/@formatjs_generated/cldr.supported-locales/default-content.js
3
+ const defaultContent = {
4
+ "aa": ["aa-ET"],
5
+ "ab": ["ab-GE"],
6
+ "af": ["af-ZA"],
7
+ "agq": ["agq-CM"],
8
+ "ak": ["ak-GH"],
9
+ "am": ["am-ET"],
10
+ "an": ["an-ES"],
11
+ "ann": ["ann-NG"],
12
+ "apc": ["apc-SY"],
13
+ "ar": ["ar-001"],
14
+ "arn": ["arn-CL"],
15
+ "as": ["as-IN"],
16
+ "asa": ["asa-TZ"],
17
+ "ast": ["ast-ES"],
18
+ "az-Arab": ["az-Arab-IR"],
19
+ "az-Cyrl": ["az-Cyrl-AZ"],
20
+ "az-Latn": ["az-Latn-AZ"],
21
+ "ba": ["ba-RU"],
22
+ "bal-Arab": ["bal-Arab-PK"],
23
+ "bal-Latn": ["bal-Latn-PK"],
24
+ "bas": ["bas-CM"],
25
+ "be": ["be-BY"],
26
+ "bem": ["bem-ZM"],
27
+ "bew": ["bew-ID"],
28
+ "bez": ["bez-TZ"],
29
+ "bg": ["bg-BG"],
30
+ "bgc": ["bgc-IN"],
31
+ "bgn": ["bgn-PK"],
32
+ "bho": ["bho-IN"],
33
+ "blo": ["blo-BJ"],
34
+ "blt": ["blt-VN"],
35
+ "bm": ["bm-ML"],
36
+ "bm-Nkoo": ["bm-Nkoo-ML"],
37
+ "bn": ["bn-BD"],
38
+ "bo": ["bo-CN"],
39
+ "bqi": ["bqi-IR"],
40
+ "br": ["br-FR"],
41
+ "brx": ["brx-IN"],
42
+ "bs-Cyrl": ["bs-Cyrl-BA"],
43
+ "bs-Latn": ["bs-Latn-BA"],
44
+ "bss": ["bss-CM"],
45
+ "bua": ["bua-RU"],
46
+ "byn": ["byn-ER"],
47
+ "ca": ["ca-ES"],
48
+ "cad": ["cad-US"],
49
+ "cch": ["cch-NG"],
50
+ "ccp": ["ccp-BD"],
51
+ "ce": ["ce-RU"],
52
+ "ceb": ["ceb-PH"],
53
+ "cgg": ["cgg-UG"],
54
+ "cho": ["cho-US"],
55
+ "chr": ["chr-US"],
56
+ "cic": ["cic-US"],
57
+ "ckb": ["ckb-IQ"],
58
+ "co": ["co-FR"],
59
+ "cop": ["cop-EG"],
60
+ "cs": ["cs-CZ"],
61
+ "csw": ["csw-CA"],
62
+ "cu": ["cu-RU"],
63
+ "cv": ["cv-RU"],
64
+ "cy": ["cy-GB"],
65
+ "da": ["da-DK"],
66
+ "dav": ["dav-KE"],
67
+ "de": ["de-DE"],
68
+ "dje": ["dje-NE"],
69
+ "doi": ["doi-IN"],
70
+ "dsb": ["dsb-DE"],
71
+ "dua": ["dua-CM"],
72
+ "dv": ["dv-MV"],
73
+ "dyo": ["dyo-SN"],
74
+ "dz": ["dz-BT"],
75
+ "ebu": ["ebu-KE"],
76
+ "ee": ["ee-GH"],
77
+ "el": ["el-GR"],
78
+ "en-Dsrt": ["en-Dsrt-US"],
79
+ "en-Shaw": ["en-Shaw-GB"],
80
+ "en": ["en-US"],
81
+ "eo": ["eo-001"],
82
+ "es": ["es-ES"],
83
+ "et": ["et-EE"],
84
+ "eu": ["eu-ES"],
85
+ "ewo": ["ewo-CM"],
86
+ "fa": ["fa-IR"],
87
+ "ff-Adlm": ["ff-Adlm-GN"],
88
+ "ff-Latn": ["ff-Latn-SN"],
89
+ "fi": ["fi-FI"],
90
+ "fil": ["fil-PH"],
91
+ "fo": ["fo-FO"],
92
+ "fr": ["fr-FR"],
93
+ "frr": ["frr-DE"],
94
+ "fur": ["fur-IT"],
95
+ "fy": ["fy-NL"],
96
+ "ga": ["ga-IE"],
97
+ "gaa": ["gaa-GH"],
98
+ "gd": ["gd-GB"],
99
+ "gez": ["gez-ET"],
100
+ "gl": ["gl-ES"],
101
+ "gn": ["gn-PY"],
102
+ "gsw": ["gsw-CH"],
103
+ "gu": ["gu-IN"],
104
+ "guz": ["guz-KE"],
105
+ "gv": ["gv-IM"],
106
+ "ha-Arab": ["ha-Arab-NG"],
107
+ "ha": ["ha-NG"],
108
+ "haw": ["haw-US"],
109
+ "he": ["he-IL"],
110
+ "hi": ["hi-IN"],
111
+ "hi-Latn": ["hi-Latn-IN"],
112
+ "hnj-Hmnp": ["hnj-Hmnp-US"],
113
+ "hr": ["hr-HR"],
114
+ "hsb": ["hsb-DE"],
115
+ "ht": ["ht-HT"],
116
+ "hu": ["hu-HU"],
117
+ "hy": ["hy-AM"],
118
+ "ia": ["ia-001"],
119
+ "id": ["id-ID"],
120
+ "ie": ["ie-EE"],
121
+ "ig": ["ig-NG"],
122
+ "ii": ["ii-CN"],
123
+ "io": ["io-001"],
124
+ "is": ["is-IS"],
125
+ "it": ["it-IT"],
126
+ "iu": ["iu-CA"],
127
+ "iu-Latn": ["iu-Latn-CA"],
128
+ "ja": ["ja-JP"],
129
+ "jbo": ["jbo-001"],
130
+ "jgo": ["jgo-CM"],
131
+ "jmc": ["jmc-TZ"],
132
+ "jv": ["jv-ID"],
133
+ "ka": ["ka-GE"],
134
+ "kaa-Cyrl": ["kaa-Cyrl-UZ"],
135
+ "kaa-Latn": ["kaa-Latn-UZ"],
136
+ "kab": ["kab-DZ"],
137
+ "kaj": ["kaj-NG"],
138
+ "kam": ["kam-KE"],
139
+ "kcg": ["kcg-NG"],
140
+ "kde": ["kde-TZ"],
141
+ "kea": ["kea-CV"],
142
+ "kek": ["kek-GT"],
143
+ "ken": ["ken-CM"],
144
+ "kgp": ["kgp-BR"],
145
+ "khq": ["khq-ML"],
146
+ "ki": ["ki-KE"],
147
+ "kk-Arab": ["kk-Arab-CN"],
148
+ "kk-Cyrl": ["kk-Cyrl-KZ"],
149
+ "kkj": ["kkj-CM"],
150
+ "kl": ["kl-GL"],
151
+ "kln": ["kln-KE"],
152
+ "km": ["km-KH"],
153
+ "kn": ["kn-IN"],
154
+ "ko": ["ko-KR"],
155
+ "kok-Deva": ["kok-Deva-IN"],
156
+ "kok-Latn": ["kok-Latn-IN"],
157
+ "kpe": ["kpe-LR"],
158
+ "ks-Arab": ["ks-Arab-IN"],
159
+ "ks-Deva": ["ks-Deva-IN"],
160
+ "ksb": ["ksb-TZ"],
161
+ "ksf": ["ksf-CM"],
162
+ "ksh": ["ksh-DE"],
163
+ "ku-Arab": ["ku-Arab-IQ"],
164
+ "ku-Latn": ["ku-Latn-TR"],
165
+ "kw": ["kw-GB"],
166
+ "kxv-Deva": ["kxv-Deva-IN"],
167
+ "kxv-Latn": ["kxv-Latn-IN"],
168
+ "kxv-Orya": ["kxv-Orya-IN"],
169
+ "kxv-Telu": ["kxv-Telu-IN"],
170
+ "ky": ["ky-KG"],
171
+ "la": ["la-VA"],
172
+ "lag": ["lag-TZ"],
173
+ "lb": ["lb-LU"],
174
+ "lg": ["lg-UG"],
175
+ "lij": ["lij-IT"],
176
+ "lkt": ["lkt-US"],
177
+ "lld": ["lld-IT"],
178
+ "lmo": ["lmo-IT"],
179
+ "ln": ["ln-CD"],
180
+ "lo": ["lo-LA"],
181
+ "lrc": ["lrc-IR"],
182
+ "lt": ["lt-LT"],
183
+ "ltg": ["ltg-LV"],
184
+ "lu": ["lu-CD"],
185
+ "luo": ["luo-KE"],
186
+ "luy": ["luy-KE"],
187
+ "lv": ["lv-LV"],
188
+ "lzz": ["lzz-TR"],
189
+ "mai": ["mai-IN"],
190
+ "mas": ["mas-KE"],
191
+ "mdf": ["mdf-RU"],
192
+ "mer": ["mer-KE"],
193
+ "mfe": ["mfe-MU"],
194
+ "mg": ["mg-MG"],
195
+ "mgh": ["mgh-MZ"],
196
+ "mgo": ["mgo-CM"],
197
+ "mhn": ["mhn-IT"],
198
+ "mi": ["mi-NZ"],
199
+ "mic": ["mic-CA"],
200
+ "mk": ["mk-MK"],
201
+ "ml": ["ml-IN"],
202
+ "mn": ["mn-MN"],
203
+ "mn-Mong": ["mn-Mong-CN"],
204
+ "mni-Beng": ["mni-Beng-IN"],
205
+ "mni-Mtei": ["mni-Mtei-IN"],
206
+ "moh": ["moh-CA"],
207
+ "mr": ["mr-IN"],
208
+ "ms-Arab": ["ms-Arab-MY"],
209
+ "ms": ["ms-MY"],
210
+ "mt": ["mt-MT"],
211
+ "mua": ["mua-CM"],
212
+ "mus": ["mus-US"],
213
+ "mww-Hmnp": ["mww-Hmnp-US"],
214
+ "my": ["my-MM"],
215
+ "myv": ["myv-RU"],
216
+ "mzn": ["mzn-IR"],
217
+ "naq": ["naq-NA"],
218
+ "nb": ["nb-NO"],
219
+ "nd": ["nd-ZW"],
220
+ "nds": ["nds-DE"],
221
+ "ne": ["ne-NP"],
222
+ "nl": ["nl-NL"],
223
+ "nmg": ["nmg-CM"],
224
+ "nn": ["nn-NO"],
225
+ "nnh": ["nnh-CM"],
226
+ "nqo": ["nqo-GN"],
227
+ "nr": ["nr-ZA"],
228
+ "nso": ["nso-ZA"],
229
+ "nus": ["nus-SS"],
230
+ "nv": ["nv-US"],
231
+ "ny": ["ny-MW"],
232
+ "nyn": ["nyn-UG"],
233
+ "oc": ["oc-FR"],
234
+ "oka": ["oka-CA"],
235
+ "om": ["om-ET"],
236
+ "or": ["or-IN"],
237
+ "os": ["os-GE"],
238
+ "osa": ["osa-US"],
239
+ "pa-Arab": ["pa-Arab-PK"],
240
+ "pa-Guru": ["pa-Guru-IN"],
241
+ "pap": ["pap-CW"],
242
+ "pcm": ["pcm-NG"],
243
+ "pi-Latn": ["pi-Latn-GB"],
244
+ "pis": ["pis-SB"],
245
+ "pl": ["pl-PL"],
246
+ "pms": ["pms-IT"],
247
+ "prg": ["prg-PL"],
248
+ "ps": ["ps-AF"],
249
+ "pt": ["pt-BR"],
250
+ "qu": ["qu-PE"],
251
+ "quc": ["quc-GT"],
252
+ "raj": ["raj-IN"],
253
+ "rhg-Rohg": ["rhg-Rohg-MM"],
254
+ "rif": ["rif-MA"],
255
+ "rm": ["rm-CH"],
256
+ "rn": ["rn-BI"],
257
+ "ro": ["ro-RO"],
258
+ "rof": ["rof-TZ"],
259
+ "ru": ["ru-RU"],
260
+ "rw": ["rw-RW"],
261
+ "rwk": ["rwk-TZ"],
262
+ "sa": ["sa-IN"],
263
+ "sah": ["sah-RU"],
264
+ "saq": ["saq-KE"],
265
+ "sat-Deva": ["sat-Deva-IN"],
266
+ "sat-Olck": ["sat-Olck-IN"],
267
+ "sbp": ["sbp-TZ"],
268
+ "sc": ["sc-IT"],
269
+ "scn": ["scn-IT"],
270
+ "sd-Arab": ["sd-Arab-PK"],
271
+ "sd-Deva": ["sd-Deva-IN"],
272
+ "sdh": ["sdh-IR"],
273
+ "se": ["se-NO"],
274
+ "seh": ["seh-MZ"],
275
+ "ses": ["ses-ML"],
276
+ "sg": ["sg-CF"],
277
+ "sgs": ["sgs-LT"],
278
+ "shi-Latn": ["shi-Latn-MA"],
279
+ "shi-Tfng": ["shi-Tfng-MA"],
280
+ "shn": ["shn-MM"],
281
+ "si": ["si-LK"],
282
+ "sid": ["sid-ET"],
283
+ "sk": ["sk-SK"],
284
+ "skr": ["skr-PK"],
285
+ "sl": ["sl-SI"],
286
+ "sma": ["sma-SE"],
287
+ "smj": ["smj-SE"],
288
+ "smn": ["smn-FI"],
289
+ "sms": ["sms-FI"],
290
+ "sn": ["sn-ZW"],
291
+ "so": ["so-SO"],
292
+ "sq": ["sq-AL"],
293
+ "sr-Cyrl": ["sr-Cyrl-RS"],
294
+ "sr-Latn": ["sr-Latn-RS"],
295
+ "ss": ["ss-ZA"],
296
+ "ssy": ["ssy-ER"],
297
+ "st": ["st-ZA"],
298
+ "su-Latn": ["su-Latn-ID"],
299
+ "suz-Deva": ["suz-Deva-NP"],
300
+ "suz-Sunu": ["suz-Sunu-NP"],
301
+ "sv": ["sv-SE"],
302
+ "sw": ["sw-TZ"],
303
+ "syr": ["syr-IQ"],
304
+ "szl": ["szl-PL"],
305
+ "ta": ["ta-IN"],
306
+ "te": ["te-IN"],
307
+ "teo": ["teo-UG"],
308
+ "tg": ["tg-TJ"],
309
+ "th": ["th-TH"],
310
+ "ti": ["ti-ET"],
311
+ "tig": ["tig-ER"],
312
+ "tk": ["tk-TM"],
313
+ "tn": ["tn-ZA"],
314
+ "to": ["to-TO"],
315
+ "tok": ["tok-001"],
316
+ "tpi": ["tpi-PG"],
317
+ "tr": ["tr-TR"],
318
+ "trv": ["trv-TW"],
319
+ "trw": ["trw-PK"],
320
+ "ts": ["ts-ZA"],
321
+ "tt": ["tt-RU"],
322
+ "twq": ["twq-NE"],
323
+ "tyv": ["tyv-RU"],
324
+ "tzm": ["tzm-MA"],
325
+ "ug": ["ug-CN"],
326
+ "uk": ["uk-UA"],
327
+ "ur": ["ur-PK"],
328
+ "uz-Arab": ["uz-Arab-AF"],
329
+ "uz-Cyrl": ["uz-Cyrl-UZ"],
330
+ "uz-Latn": ["uz-Latn-UZ"],
331
+ "vai-Latn": ["vai-Latn-LR"],
332
+ "vai-Vaii": ["vai-Vaii-LR"],
333
+ "ve": ["ve-ZA"],
334
+ "vec": ["vec-IT"],
335
+ "vi": ["vi-VN"],
336
+ "vmw": ["vmw-MZ"],
337
+ "vo": ["vo-001"],
338
+ "vun": ["vun-TZ"],
339
+ "wa": ["wa-BE"],
340
+ "wae": ["wae-CH"],
341
+ "wal": ["wal-ET"],
342
+ "wbp": ["wbp-AU"],
343
+ "wo": ["wo-SN"],
344
+ "xh": ["xh-ZA"],
345
+ "xnr": ["xnr-IN"],
346
+ "xog": ["xog-UG"],
347
+ "yav": ["yav-CM"],
348
+ "yi": ["yi-UA"],
349
+ "yo": ["yo-NG"],
350
+ "yrl": ["yrl-BR"],
351
+ "yue-Hans": ["yue-Hans-CN"],
352
+ "yue-Hant": ["yue-Hant-HK"],
353
+ "za": ["za-CN"],
354
+ "zgh": ["zgh-MA"],
355
+ "zh-Hans": ["zh-Hans-CN"],
356
+ "zh-Hant": ["zh-Hant-TW"],
357
+ "zh-Latn": ["zh-Latn-CN"],
358
+ "zu": ["zu-ZA"]
359
+ };
360
+ //#endregion
361
+ //#region packages/ecma402-abstract/registerLocaleData.js
362
+ const explicitLocales = /* @__PURE__ */ new WeakMap();
363
+ function registerLocaleData(locale, data, localeData, availableLocales) {
364
+ let loaded = explicitLocales.get(localeData);
365
+ if (!loaded) {
366
+ loaded = /* @__PURE__ */ new Set();
367
+ explicitLocales.set(localeData, loaded);
368
+ }
369
+ loaded.add(locale);
370
+ const locales = [locale, ...defaultContent[locale] || []];
371
+ for (const tag of locales) {
372
+ if (tag === locale || !loaded.has(tag) || localeData[tag] === void 0) localeData[tag] = data;
373
+ availableLocales.add(tag);
374
+ }
375
+ for (const tag of locales) {
376
+ const parts = tag.split("-");
377
+ const fallbacks = [];
378
+ while (parts.length > 1) {
379
+ if (parts.length > 2 && parts[1].length === 4) fallbacks.push([parts[0], ...parts.slice(2)].join("-"));
380
+ parts.pop();
381
+ fallbacks.push(parts.join("-"));
382
+ }
383
+ for (const fallback of fallbacks) {
384
+ if (localeData[fallback] === void 0) localeData[fallback] = localeData[tag];
385
+ availableLocales.add(fallback);
386
+ }
387
+ }
388
+ }
389
+ //#endregion
2
390
  //#region packages/ecma402-abstract/CanonicalizeLocaleList.js
3
391
  /**
4
392
  * http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
@@ -27,7 +415,7 @@ function ToString(o) {
27
415
  * @param fallback
28
416
  */
29
417
  function GetOption(opts, prop, type, values, fallback) {
30
- if (typeof opts !== "object") throw new TypeError("Options must be an object");
418
+ if (opts === null || typeof opts !== "object" && typeof opts !== "function") throw new TypeError("Options must be an object");
31
419
  let value = opts[prop];
32
420
  if (value !== void 0) {
33
421
  if (type !== "boolean" && type !== "string") throw new TypeError("invalid type");
@@ -41,13 +429,15 @@ function GetOption(opts, prop, type, values, fallback) {
41
429
  //#endregion
42
430
  //#region packages/ecma402-abstract/GetOptionsObject.js
43
431
  /**
44
- * https://tc39.es/ecma402/#sec-getoptionsobject
432
+ * ECMA-262 §7.3.36 GetOptionsObject, steps 2–3.
433
+ * https://tc39.es/ecma262/#sec-getoptionsobject
434
+ * https://github.com/tc39/ecma262/blob/dcf59856a8184792a9e42f0ffb7dc064094a5dcc/spec.html#L7008-L7010
45
435
  * @param options
46
436
  * @returns
47
437
  */
48
438
  function GetOptionsObject(options) {
49
439
  if (typeof options === "undefined") return Object.create(null);
50
- if (typeof options === "object") return options;
440
+ if (options !== null && (typeof options === "object" || typeof options === "function")) return options;
51
441
  throw new TypeError("Options must be an object");
52
442
  }
53
443
  //#endregion
@@ -212,18 +602,11 @@ function validateInstance(instance, method) {
212
602
  * @param iterable list
213
603
  */
214
604
  function stringListFromIterable(iterable) {
215
- if (typeof iterable !== "object") return [];
605
+ if (iterable === void 0) return [];
216
606
  const elements = [];
217
- const iterator = iterable[Symbol.iterator]();
218
- let result;
219
- while (true) {
220
- result = iterator.next();
221
- if (result.done) break;
222
- if (typeof result.value !== "string") {
223
- const nextValue = result.value;
224
- throw new TypeError(`Iterable yielded ${nextValue} which is not a string`);
225
- }
226
- elements.push(result.value);
607
+ for (const value of iterable) {
608
+ if (typeof value !== "string") throw new TypeError("Iterable yielded a non-string value");
609
+ elements.push(value);
227
610
  }
228
611
  return elements;
229
612
  }
@@ -341,11 +724,8 @@ var ListFormat = class ListFormat {
341
724
  }
342
725
  static __addLocaleData(...data) {
343
726
  for (const { data: d, locale } of data) {
344
- const minimizedLocale = new Intl.Locale(locale).minimize().toString();
345
- ListFormat.localeData[locale] = ListFormat.localeData[minimizedLocale] = d;
346
- ListFormat.availableLocales.add(minimizedLocale);
347
- ListFormat.availableLocales.add(locale);
348
- if (!ListFormat.__defaultLocale) ListFormat.__defaultLocale = minimizedLocale;
727
+ registerLocaleData(locale, d, ListFormat.localeData, ListFormat.availableLocales);
728
+ if (!ListFormat.__defaultLocale) ListFormat.__defaultLocale = locale;
349
729
  }
350
730
  }
351
731
  static {