@formatjs/intl-listformat 8.3.1 → 8.3.2
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 +103 -68
- package/index.js +264 -84
- package/index.js.map +1 -0
- package/package.json +4 -5
- package/polyfill-force.d.ts +1 -1
- package/polyfill-force.js +398 -2
- package/polyfill-force.js.map +1 -0
- package/polyfill.d.ts +1 -1
- package/polyfill.iife.js +4688 -5452
- package/polyfill.js +983 -3
- package/polyfill.js.map +1 -0
- package/should-polyfill.d.ts +5 -1
- package/should-polyfill.js +583 -8
- package/should-polyfill.js.map +1 -0
- package/supported-locales.generated.d.ts +0 -1
- package/supported-locales.generated.js +0 -573
package/index.d.ts
CHANGED
|
@@ -1,72 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* For information about this option, see
|
|
7
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation.
|
|
8
|
-
*/
|
|
9
|
-
localeMatcher?: "best fit" | "lookup";
|
|
10
|
-
/**
|
|
11
|
-
* The format of output message.
|
|
12
|
-
* Possible values are :
|
|
13
|
-
* - "conjunction" that stands for "and"-based lists (default, e.g., "A, B, and C")
|
|
14
|
-
* - "disjunction" that stands for "or"-based lists (e.g., "A, B, or C").
|
|
15
|
-
* - "unit" stands for lists of values with units (e.g., "5 pounds, 12 ounces").
|
|
16
|
-
*/
|
|
17
|
-
type?: "conjunction" | "disjunction" | "unit";
|
|
18
|
-
/**
|
|
19
|
-
* The length of the formatted message.
|
|
20
|
-
* Possible values are:
|
|
21
|
-
* - "long" (default, e.g., "A, B, and C");
|
|
22
|
-
* - "short" (e.g., "A, B, C"), or
|
|
23
|
-
* - "narrow" (e.g., "A B C").
|
|
24
|
-
* When style is "short" or "narrow", "unit" is the only allowed value for the type option.
|
|
25
|
-
*/
|
|
26
|
-
style?: "long" | "short" | "narrow";
|
|
1
|
+
//#region packages/ecma402-abstract/types/core.d.ts
|
|
2
|
+
type Locale = string;
|
|
3
|
+
interface LocaleData<T> {
|
|
4
|
+
data: T;
|
|
5
|
+
locale: Locale;
|
|
27
6
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The format of output message.
|
|
37
|
-
* Possible values are :
|
|
38
|
-
* - "conjunction" that stands for "and"-based lists (default, e.g., "A, B, and C")
|
|
39
|
-
* - "disjunction" that stands for "or"-based lists (e.g., "A, B, or C").
|
|
40
|
-
* - "unit" stands for lists of values with units (e.g., "5 pounds, 12 ounces").
|
|
41
|
-
*/
|
|
42
|
-
type: "conjunction" | "disjunction" | "unit";
|
|
43
|
-
/**
|
|
44
|
-
* The length of the formatted message.
|
|
45
|
-
* Possible values are:
|
|
46
|
-
* - "long" (default, e.g., "A, B, and C");
|
|
47
|
-
* - "short" (e.g., "A, B, C"), or
|
|
48
|
-
* - "narrow" (e.g., "A B C").
|
|
49
|
-
* When style is "short" or "narrow", "unit" is the only allowed value for the type option.
|
|
50
|
-
*/
|
|
51
|
-
style: "long" | "short" | "narrow";
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region packages/ecma402-abstract/types/list.d.ts
|
|
9
|
+
type ListPatternLocaleData = LocaleData<ListPatternFieldsData>;
|
|
10
|
+
interface ListPatternFieldsData {
|
|
11
|
+
conjunction?: ListPatternData;
|
|
12
|
+
disjunction?: ListPatternData;
|
|
13
|
+
unit?: ListPatternData;
|
|
52
14
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
15
|
+
interface ListPattern {
|
|
16
|
+
start: string;
|
|
17
|
+
middle: string;
|
|
18
|
+
end: string;
|
|
19
|
+
pair: string;
|
|
57
20
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
resolvedOptions(): ResolvedIntlListFormatOptions;
|
|
63
|
-
static supportedLocalesOf(locales: string | string[], options?: Pick<IntlListFormatOptions, "localeMatcher">): string[];
|
|
64
|
-
static __addLocaleData(...data: ListPatternLocaleData[]): void;
|
|
65
|
-
static localeData: Record<string, ListPatternFieldsData | undefined>;
|
|
66
|
-
private static availableLocales;
|
|
67
|
-
private static __defaultLocale;
|
|
68
|
-
private static getDefaultLocale;
|
|
69
|
-
private static relevantExtensionKeys;
|
|
70
|
-
static polyfilled: boolean;
|
|
71
|
-
private static readonly __INTERNAL_SLOT_MAP__;
|
|
21
|
+
interface ListPatternData {
|
|
22
|
+
long: ListPattern;
|
|
23
|
+
short?: ListPattern;
|
|
24
|
+
narrow?: ListPattern;
|
|
72
25
|
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region packages/ecma402-abstract/utils.d.ts
|
|
28
|
+
interface LiteralPart {
|
|
29
|
+
type: "literal";
|
|
30
|
+
value: string;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region packages/intl-listformat/index.d.ts
|
|
34
|
+
interface IntlListFormatOptions {
|
|
35
|
+
/**
|
|
36
|
+
* The locale matching algorithm to use.
|
|
37
|
+
* Possible values are "lookup" and "best fit"; the default is "best fit".
|
|
38
|
+
* For information about this option, see
|
|
39
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation.
|
|
40
|
+
*/
|
|
41
|
+
localeMatcher?: "best fit" | "lookup";
|
|
42
|
+
/**
|
|
43
|
+
* The format of output message.
|
|
44
|
+
* Possible values are :
|
|
45
|
+
* - "conjunction" that stands for "and"-based lists (default, e.g., "A, B, and C")
|
|
46
|
+
* - "disjunction" that stands for "or"-based lists (e.g., "A, B, or C").
|
|
47
|
+
* - "unit" stands for lists of values with units (e.g., "5 pounds, 12 ounces").
|
|
48
|
+
*/
|
|
49
|
+
type?: "conjunction" | "disjunction" | "unit";
|
|
50
|
+
/**
|
|
51
|
+
* The length of the formatted message.
|
|
52
|
+
* Possible values are:
|
|
53
|
+
* - "long" (default, e.g., "A, B, and C");
|
|
54
|
+
* - "short" (e.g., "A, B, C"), or
|
|
55
|
+
* - "narrow" (e.g., "A B C").
|
|
56
|
+
* When style is "short" or "narrow", "unit" is the only allowed value for the type option.
|
|
57
|
+
*/
|
|
58
|
+
style?: "long" | "short" | "narrow";
|
|
59
|
+
}
|
|
60
|
+
interface ResolvedIntlListFormatOptions {
|
|
61
|
+
/**
|
|
62
|
+
* A string with a BCP 47 language tag, or an array of such strings.
|
|
63
|
+
* For the general form and interpretation of the locales argument,
|
|
64
|
+
* see the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) page.
|
|
65
|
+
*/
|
|
66
|
+
locale: string;
|
|
67
|
+
/**
|
|
68
|
+
* The format of output message.
|
|
69
|
+
* Possible values are :
|
|
70
|
+
* - "conjunction" that stands for "and"-based lists (default, e.g., "A, B, and C")
|
|
71
|
+
* - "disjunction" that stands for "or"-based lists (e.g., "A, B, or C").
|
|
72
|
+
* - "unit" stands for lists of values with units (e.g., "5 pounds, 12 ounces").
|
|
73
|
+
*/
|
|
74
|
+
type: "conjunction" | "disjunction" | "unit";
|
|
75
|
+
/**
|
|
76
|
+
* The length of the formatted message.
|
|
77
|
+
* Possible values are:
|
|
78
|
+
* - "long" (default, e.g., "A, B, and C");
|
|
79
|
+
* - "short" (e.g., "A, B, C"), or
|
|
80
|
+
* - "narrow" (e.g., "A B C").
|
|
81
|
+
* When style is "short" or "narrow", "unit" is the only allowed value for the type option.
|
|
82
|
+
*/
|
|
83
|
+
style: "long" | "short" | "narrow";
|
|
84
|
+
}
|
|
85
|
+
type Part<T = string> = LiteralPart | ElementPart | ElementPart<T>;
|
|
86
|
+
interface ElementPart<T = string> {
|
|
87
|
+
type: "element";
|
|
88
|
+
value: T;
|
|
89
|
+
}
|
|
90
|
+
declare class ListFormat {
|
|
91
|
+
constructor(locales?: string | string[], options?: IntlListFormatOptions);
|
|
92
|
+
format(elements: Iterable<string>): string;
|
|
93
|
+
formatToParts(elements: Iterable<string>): Part[];
|
|
94
|
+
resolvedOptions(): ResolvedIntlListFormatOptions;
|
|
95
|
+
static supportedLocalesOf(locales: string | string[], options?: Pick<IntlListFormatOptions, "localeMatcher">): string[];
|
|
96
|
+
static __addLocaleData(...data: ListPatternLocaleData[]): void;
|
|
97
|
+
static localeData: Record<string, ListPatternFieldsData | undefined>;
|
|
98
|
+
private static availableLocales;
|
|
99
|
+
private static __defaultLocale;
|
|
100
|
+
private static getDefaultLocale;
|
|
101
|
+
private static relevantExtensionKeys;
|
|
102
|
+
static polyfilled: boolean;
|
|
103
|
+
private static readonly __INTERNAL_SLOT_MAP__;
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { ElementPart, IntlListFormatOptions, Part, ResolvedIntlListFormatOptions, ListFormat as default };
|
|
107
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -1,9 +1,212 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { LookupSupportedLocales, ResolveLocale } from "@formatjs/intl-localematcher";
|
|
2
|
+
//#region packages/ecma402-abstract/CanonicalizeLocaleList.js
|
|
3
|
+
/**
|
|
4
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
|
|
5
|
+
* @param locales
|
|
6
|
+
*/
|
|
7
|
+
function CanonicalizeLocaleList(locales) {
|
|
8
|
+
return Intl.getCanonicalLocales(locales);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region packages/ecma262-abstract/ToString.js
|
|
12
|
+
/**
|
|
13
|
+
* https://tc39.es/ecma262/#sec-tostring
|
|
14
|
+
*/
|
|
15
|
+
function ToString(o) {
|
|
16
|
+
if (typeof o === "symbol") throw TypeError("Cannot convert a Symbol value to a string");
|
|
17
|
+
return String(o);
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region packages/ecma402-abstract/GetOption.js
|
|
21
|
+
/**
|
|
22
|
+
* https://tc39.es/ecma402/#sec-getoption
|
|
23
|
+
* @param opts
|
|
24
|
+
* @param prop
|
|
25
|
+
* @param type
|
|
26
|
+
* @param values
|
|
27
|
+
* @param fallback
|
|
28
|
+
*/
|
|
29
|
+
function GetOption(opts, prop, type, values, fallback) {
|
|
30
|
+
if (typeof opts !== "object") throw new TypeError("Options must be an object");
|
|
31
|
+
let value = opts[prop];
|
|
32
|
+
if (value !== void 0) {
|
|
33
|
+
if (type !== "boolean" && type !== "string") throw new TypeError("invalid type");
|
|
34
|
+
if (type === "boolean") value = Boolean(value);
|
|
35
|
+
if (type === "string") value = ToString(value);
|
|
36
|
+
if (values !== void 0 && !values.filter((val) => val == value).length) throw new RangeError(`${value} is not within ${values.join(", ")}`);
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
return fallback;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region packages/ecma402-abstract/GetOptionsObject.js
|
|
43
|
+
/**
|
|
44
|
+
* https://tc39.es/ecma402/#sec-getoptionsobject
|
|
45
|
+
* @param options
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
function GetOptionsObject(options) {
|
|
49
|
+
if (typeof options === "undefined") return Object.create(null);
|
|
50
|
+
if (typeof options === "object") return options;
|
|
51
|
+
throw new TypeError("Options must be an object");
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
|
|
55
|
+
function memoize(fn, options) {
|
|
56
|
+
const cache = options && options.cache ? options.cache : cacheDefault;
|
|
57
|
+
const serializer = options && options.serializer ? options.serializer : serializerDefault;
|
|
58
|
+
return (options && options.strategy ? options.strategy : strategyDefault)(fn, {
|
|
59
|
+
cache,
|
|
60
|
+
serializer
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function isPrimitive(value) {
|
|
64
|
+
return value == null || typeof value === "number" || typeof value === "boolean";
|
|
65
|
+
}
|
|
66
|
+
function monadic(fn, cache, serializer, arg) {
|
|
67
|
+
const cacheKey = isPrimitive(arg) ? arg : serializer(arg);
|
|
68
|
+
let computedValue = cache.get(cacheKey);
|
|
69
|
+
if (typeof computedValue === "undefined") {
|
|
70
|
+
computedValue = fn.call(this, arg);
|
|
71
|
+
cache.set(cacheKey, computedValue);
|
|
72
|
+
}
|
|
73
|
+
return computedValue;
|
|
74
|
+
}
|
|
75
|
+
function variadic(fn, cache, serializer) {
|
|
76
|
+
const args = Array.prototype.slice.call(arguments, 3);
|
|
77
|
+
const cacheKey = serializer(args);
|
|
78
|
+
let computedValue = cache.get(cacheKey);
|
|
79
|
+
if (typeof computedValue === "undefined") {
|
|
80
|
+
computedValue = fn.apply(this, args);
|
|
81
|
+
cache.set(cacheKey, computedValue);
|
|
82
|
+
}
|
|
83
|
+
return computedValue;
|
|
84
|
+
}
|
|
85
|
+
function assemble(fn, context, strategy, cache, serialize) {
|
|
86
|
+
return strategy.bind(context, fn, cache, serialize);
|
|
87
|
+
}
|
|
88
|
+
function strategyDefault(fn, options) {
|
|
89
|
+
const strategy = fn.length === 1 ? monadic : variadic;
|
|
90
|
+
return assemble(fn, this, strategy, options.cache.create(), options.serializer);
|
|
91
|
+
}
|
|
92
|
+
function strategyVariadic(fn, options) {
|
|
93
|
+
return assemble(fn, this, variadic, options.cache.create(), options.serializer);
|
|
94
|
+
}
|
|
95
|
+
function strategyMonadic(fn, options) {
|
|
96
|
+
return assemble(fn, this, monadic, options.cache.create(), options.serializer);
|
|
97
|
+
}
|
|
98
|
+
const serializerDefault = function() {
|
|
99
|
+
return JSON.stringify(arguments);
|
|
100
|
+
};
|
|
101
|
+
var ObjectWithoutPrototypeCache = class {
|
|
102
|
+
constructor() {
|
|
103
|
+
this.cache = Object.create(null);
|
|
104
|
+
}
|
|
105
|
+
get(key) {
|
|
106
|
+
return this.cache[key];
|
|
107
|
+
}
|
|
108
|
+
set(key, value) {
|
|
109
|
+
this.cache[key] = value;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const cacheDefault = { create: function create() {
|
|
113
|
+
return new ObjectWithoutPrototypeCache();
|
|
114
|
+
} };
|
|
115
|
+
const strategies = {
|
|
116
|
+
variadic: strategyVariadic,
|
|
117
|
+
monadic: strategyMonadic
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region packages/ecma402-abstract/utils.js
|
|
121
|
+
function setInternalSlot(map, pl, field, value) {
|
|
122
|
+
if (!map.get(pl)) map.set(pl, Object.create(null));
|
|
123
|
+
const slots = map.get(pl);
|
|
124
|
+
slots[field] = value;
|
|
125
|
+
}
|
|
126
|
+
function getInternalSlot(map, pl, field) {
|
|
127
|
+
return getMultiInternalSlots(map, pl, field)[field];
|
|
128
|
+
}
|
|
129
|
+
function getMultiInternalSlots(map, pl, ...fields) {
|
|
130
|
+
const slots = map.get(pl);
|
|
131
|
+
if (!slots) throw new TypeError(`${pl} InternalSlot has not been initialized`);
|
|
132
|
+
return fields.reduce((all, f) => {
|
|
133
|
+
all[f] = slots[f];
|
|
134
|
+
return all;
|
|
135
|
+
}, Object.create(null));
|
|
136
|
+
}
|
|
137
|
+
function isLiteralPart(patternPart) {
|
|
138
|
+
return patternPart.type === "literal";
|
|
139
|
+
}
|
|
140
|
+
function invariant(condition, message, Err = Error) {
|
|
141
|
+
if (!condition) throw new Err(message);
|
|
142
|
+
}
|
|
143
|
+
memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
|
|
144
|
+
memoize((...args) => new Intl.PluralRules(...args), { strategy: strategies.variadic });
|
|
145
|
+
memoize((...args) => new Intl.Locale(...args), { strategy: strategies.variadic });
|
|
146
|
+
memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic });
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region packages/ecma402-abstract/PartitionPattern.js
|
|
149
|
+
/**
|
|
150
|
+
* Partition a pattern into a list of literals and placeholders
|
|
151
|
+
* https://tc39.es/ecma402/#sec-partitionpattern
|
|
152
|
+
* @param pattern
|
|
153
|
+
*/
|
|
154
|
+
function PartitionPattern(pattern) {
|
|
155
|
+
const result = [];
|
|
156
|
+
let beginIndex = pattern.indexOf("{");
|
|
157
|
+
let endIndex = 0;
|
|
158
|
+
let nextIndex = 0;
|
|
159
|
+
const length = pattern.length;
|
|
160
|
+
while (beginIndex < pattern.length && beginIndex > -1) {
|
|
161
|
+
endIndex = pattern.indexOf("}", beginIndex);
|
|
162
|
+
invariant(endIndex > beginIndex, `Invalid pattern ${pattern}`);
|
|
163
|
+
if (beginIndex > nextIndex) result.push({
|
|
164
|
+
type: "literal",
|
|
165
|
+
value: pattern.substring(nextIndex, beginIndex)
|
|
166
|
+
});
|
|
167
|
+
result.push({
|
|
168
|
+
type: pattern.substring(beginIndex + 1, endIndex),
|
|
169
|
+
value: void 0
|
|
170
|
+
});
|
|
171
|
+
nextIndex = endIndex + 1;
|
|
172
|
+
beginIndex = pattern.indexOf("{", nextIndex);
|
|
6
173
|
}
|
|
174
|
+
if (nextIndex < length) result.push({
|
|
175
|
+
type: "literal",
|
|
176
|
+
value: pattern.substring(nextIndex, length)
|
|
177
|
+
});
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region packages/ecma262-abstract/ToObject.js
|
|
182
|
+
/**
|
|
183
|
+
* https://tc39.es/ecma262/#sec-toobject
|
|
184
|
+
*/
|
|
185
|
+
function ToObject(arg) {
|
|
186
|
+
if (arg == null) throw new TypeError("undefined/null cannot be converted to object");
|
|
187
|
+
return Object(arg);
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region packages/ecma402-abstract/SupportedLocales.js
|
|
191
|
+
/**
|
|
192
|
+
* https://tc39.es/ecma402/#sec-supportedlocales
|
|
193
|
+
* @param availableLocales
|
|
194
|
+
* @param requestedLocales
|
|
195
|
+
* @param options
|
|
196
|
+
*/
|
|
197
|
+
function SupportedLocales(availableLocales, requestedLocales, options) {
|
|
198
|
+
let matcher = "best fit";
|
|
199
|
+
if (options !== void 0) {
|
|
200
|
+
options = ToObject(options);
|
|
201
|
+
matcher = GetOption(options, "localeMatcher", "string", ["lookup", "best fit"], "best fit");
|
|
202
|
+
}
|
|
203
|
+
if (matcher === "best fit") return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
|
|
204
|
+
return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region packages/intl-listformat/index.ts
|
|
208
|
+
function validateInstance(instance, method) {
|
|
209
|
+
if (!(instance instanceof ListFormat)) throw new TypeError(`Method Intl.ListFormat.prototype.${method} called on incompatible receiver ${String(instance)}`);
|
|
7
210
|
}
|
|
8
211
|
/**
|
|
9
212
|
* https://tc39.es/proposal-intl-list-format/#sec-createstringlistfromiterable
|
|
@@ -27,39 +230,27 @@ function stringListFromIterable(iterable) {
|
|
|
27
230
|
}
|
|
28
231
|
function createPartsFromList(internalSlotMap, lf, list) {
|
|
29
232
|
const size = list.length;
|
|
30
|
-
if (size === 0)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (size === 2) {
|
|
34
|
-
const pattern = getInternalSlot(internalSlotMap, lf, "templatePair");
|
|
35
|
-
const first = {
|
|
233
|
+
if (size === 0) return [];
|
|
234
|
+
if (size === 2) return deconstructPattern(getInternalSlot(internalSlotMap, lf, "templatePair"), {
|
|
235
|
+
"0": {
|
|
36
236
|
type: "element",
|
|
37
237
|
value: list[0]
|
|
38
|
-
}
|
|
39
|
-
|
|
238
|
+
},
|
|
239
|
+
"1": {
|
|
40
240
|
type: "element",
|
|
41
241
|
value: list[1]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"1": second
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
const last = {
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
let parts = {
|
|
49
245
|
type: "element",
|
|
50
246
|
value: list[size - 1]
|
|
51
247
|
};
|
|
52
|
-
let parts = last;
|
|
53
248
|
let i = size - 2;
|
|
54
249
|
while (i >= 0) {
|
|
55
250
|
let pattern;
|
|
56
|
-
if (i === 0)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
pattern = getInternalSlot(internalSlotMap, lf, "templateMiddle");
|
|
60
|
-
} else {
|
|
61
|
-
pattern = getInternalSlot(internalSlotMap, lf, "templateEnd");
|
|
62
|
-
}
|
|
251
|
+
if (i === 0) pattern = getInternalSlot(internalSlotMap, lf, "templateStart");
|
|
252
|
+
else if (i < size - 2) pattern = getInternalSlot(internalSlotMap, lf, "templateMiddle");
|
|
253
|
+
else pattern = getInternalSlot(internalSlotMap, lf, "templateEnd");
|
|
63
254
|
const head = {
|
|
64
255
|
type: "element",
|
|
65
256
|
value: list[i]
|
|
@@ -77,37 +268,27 @@ function deconstructPattern(pattern, placeables) {
|
|
|
77
268
|
const result = [];
|
|
78
269
|
for (const patternPart of patternParts) {
|
|
79
270
|
const { type: part } = patternPart;
|
|
80
|
-
if (isLiteralPart(patternPart)) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} else {
|
|
271
|
+
if (isLiteralPart(patternPart)) result.push({
|
|
272
|
+
type: "literal",
|
|
273
|
+
value: patternPart.value
|
|
274
|
+
});
|
|
275
|
+
else {
|
|
86
276
|
invariant(part in placeables, `${part} is missing from placables`);
|
|
87
277
|
const subst = placeables[part];
|
|
88
|
-
if (Array.isArray(subst))
|
|
89
|
-
|
|
90
|
-
} else {
|
|
91
|
-
result.push(subst);
|
|
92
|
-
}
|
|
278
|
+
if (Array.isArray(subst)) result.push(...subst);
|
|
279
|
+
else result.push(subst);
|
|
93
280
|
}
|
|
94
281
|
}
|
|
95
282
|
return result;
|
|
96
283
|
}
|
|
97
|
-
|
|
284
|
+
var ListFormat = class ListFormat {
|
|
98
285
|
constructor(locales, options) {
|
|
99
|
-
|
|
100
|
-
// Cannot use `new.target` bc of IE11 & TS transpiles it to something else
|
|
101
|
-
const newTarget = this && this instanceof ListFormat ? this.constructor : void 0;
|
|
102
|
-
if (!newTarget) {
|
|
103
|
-
throw new TypeError("Intl.ListFormat must be called with 'new'");
|
|
104
|
-
}
|
|
286
|
+
if (!(this && this instanceof ListFormat ? this.constructor : void 0)) throw new TypeError("Intl.ListFormat must be called with 'new'");
|
|
105
287
|
setInternalSlot(ListFormat.__INTERNAL_SLOT_MAP__, this, "initializedListFormat", true);
|
|
106
288
|
const requestedLocales = CanonicalizeLocaleList(locales);
|
|
107
289
|
const opt = Object.create(null);
|
|
108
290
|
const opts = GetOptionsObject(options);
|
|
109
|
-
|
|
110
|
-
opt.localeMatcher = matcher;
|
|
291
|
+
opt.localeMatcher = GetOption(opts, "localeMatcher", "string", ["best fit", "lookup"], "best fit");
|
|
111
292
|
const { localeData } = ListFormat;
|
|
112
293
|
const r = ResolveLocale(ListFormat.availableLocales, requestedLocales, opt, ListFormat.relevantExtensionKeys, localeData, ListFormat.getDefaultLocale);
|
|
113
294
|
setInternalSlot(ListFormat.__INTERNAL_SLOT_MAP__, this, "locale", r.locale);
|
|
@@ -126,8 +307,7 @@ export default class ListFormat {
|
|
|
126
307
|
const { dataLocale } = r;
|
|
127
308
|
const dataLocaleData = localeData[dataLocale];
|
|
128
309
|
invariant(!!dataLocaleData, `Missing locale data for ${dataLocale}`);
|
|
129
|
-
const
|
|
130
|
-
const templates = dataLocaleTypes[style];
|
|
310
|
+
const templates = dataLocaleData[type][style];
|
|
131
311
|
setInternalSlot(ListFormat.__INTERNAL_SLOT_MAP__, this, "templatePair", templates.pair);
|
|
132
312
|
setInternalSlot(ListFormat.__INTERNAL_SLOT_MAP__, this, "templateStart", templates.start);
|
|
133
313
|
setInternalSlot(ListFormat.__INTERNAL_SLOT_MAP__, this, "templateMiddle", templates.middle);
|
|
@@ -137,24 +317,16 @@ export default class ListFormat {
|
|
|
137
317
|
validateInstance(this, "format");
|
|
138
318
|
let result = "";
|
|
139
319
|
const parts = createPartsFromList(ListFormat.__INTERNAL_SLOT_MAP__, this, stringListFromIterable(elements));
|
|
140
|
-
if (!Array.isArray(parts))
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
for (const p of parts) {
|
|
144
|
-
result += p.value;
|
|
145
|
-
}
|
|
320
|
+
if (!Array.isArray(parts)) return parts.value;
|
|
321
|
+
for (const p of parts) result += p.value;
|
|
146
322
|
return result;
|
|
147
323
|
}
|
|
148
324
|
formatToParts(elements) {
|
|
149
325
|
validateInstance(this, "format");
|
|
150
326
|
const parts = createPartsFromList(ListFormat.__INTERNAL_SLOT_MAP__, this, stringListFromIterable(elements));
|
|
151
|
-
if (!Array.isArray(parts))
|
|
152
|
-
return [parts];
|
|
153
|
-
}
|
|
327
|
+
if (!Array.isArray(parts)) return [parts];
|
|
154
328
|
const result = [];
|
|
155
|
-
for (const part of parts) {
|
|
156
|
-
result.push({ ...part });
|
|
157
|
-
}
|
|
329
|
+
for (const part of parts) result.push({ ...part });
|
|
158
330
|
return result;
|
|
159
331
|
}
|
|
160
332
|
resolvedOptions() {
|
|
@@ -166,7 +338,6 @@ export default class ListFormat {
|
|
|
166
338
|
};
|
|
167
339
|
}
|
|
168
340
|
static supportedLocalesOf(locales, options) {
|
|
169
|
-
// test262/test/intl402/ListFormat/constructor/supportedLocalesOf/result-type.js
|
|
170
341
|
return SupportedLocales(ListFormat.availableLocales, CanonicalizeLocaleList(locales), options);
|
|
171
342
|
}
|
|
172
343
|
static __addLocaleData(...data) {
|
|
@@ -175,39 +346,44 @@ export default class ListFormat {
|
|
|
175
346
|
ListFormat.localeData[locale] = ListFormat.localeData[minimizedLocale] = d;
|
|
176
347
|
ListFormat.availableLocales.add(minimizedLocale);
|
|
177
348
|
ListFormat.availableLocales.add(locale);
|
|
178
|
-
if (!ListFormat.__defaultLocale)
|
|
179
|
-
ListFormat.__defaultLocale = minimizedLocale;
|
|
180
|
-
}
|
|
349
|
+
if (!ListFormat.__defaultLocale) ListFormat.__defaultLocale = minimizedLocale;
|
|
181
350
|
}
|
|
182
351
|
}
|
|
183
|
-
static
|
|
184
|
-
|
|
185
|
-
|
|
352
|
+
static {
|
|
353
|
+
this.localeData = {};
|
|
354
|
+
}
|
|
355
|
+
static {
|
|
356
|
+
this.availableLocales = /* @__PURE__ */ new Set();
|
|
357
|
+
}
|
|
358
|
+
static {
|
|
359
|
+
this.__defaultLocale = "";
|
|
360
|
+
}
|
|
186
361
|
static getDefaultLocale() {
|
|
187
362
|
return ListFormat.__defaultLocale;
|
|
188
363
|
}
|
|
189
|
-
static
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
// IE11 does not have Symbol
|
|
195
|
-
if (typeof Symbol !== "undefined") {
|
|
196
|
-
Object.defineProperty(ListFormat.prototype, Symbol.toStringTag, {
|
|
197
|
-
value: "Intl.ListFormat",
|
|
198
|
-
writable: false,
|
|
199
|
-
enumerable: false,
|
|
200
|
-
configurable: true
|
|
201
|
-
});
|
|
364
|
+
static {
|
|
365
|
+
this.relevantExtensionKeys = [];
|
|
366
|
+
}
|
|
367
|
+
static {
|
|
368
|
+
this.polyfilled = true;
|
|
202
369
|
}
|
|
203
|
-
|
|
370
|
+
static {
|
|
371
|
+
this.__INTERNAL_SLOT_MAP__ = /* @__PURE__ */ new WeakMap();
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
try {
|
|
375
|
+
if (typeof Symbol !== "undefined") Object.defineProperty(ListFormat.prototype, Symbol.toStringTag, {
|
|
376
|
+
value: "Intl.ListFormat",
|
|
377
|
+
writable: false,
|
|
378
|
+
enumerable: false,
|
|
379
|
+
configurable: true
|
|
380
|
+
});
|
|
204
381
|
Object.defineProperty(ListFormat.prototype.constructor, "length", {
|
|
205
382
|
value: 0,
|
|
206
383
|
writable: false,
|
|
207
384
|
enumerable: false,
|
|
208
385
|
configurable: true
|
|
209
386
|
});
|
|
210
|
-
// https://github.com/tc39/test262/blob/master/test/intl402/ListFormat/constructor/supportedLocalesOf/length.js
|
|
211
387
|
Object.defineProperty(ListFormat.supportedLocalesOf, "length", {
|
|
212
388
|
value: 1,
|
|
213
389
|
writable: false,
|
|
@@ -215,3 +391,7 @@ try {
|
|
|
215
391
|
configurable: true
|
|
216
392
|
});
|
|
217
393
|
} catch {}
|
|
394
|
+
//#endregion
|
|
395
|
+
export { ListFormat as default };
|
|
396
|
+
|
|
397
|
+
//# sourceMappingURL=index.js.map
|