@formatjs/intl-durationformat 0.13.1 → 0.13.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 +4 -1
- package/index.js +205 -133
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/polyfill-force.js +220 -139
- package/polyfill-force.js.map +1 -1
- package/polyfill.js +221 -140
- package/polyfill.js.map +1 -1
- package/should-polyfill.js +1 -1
- package/should-polyfill.js.map +1 -1
package/polyfill-force.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FilterLocales, ResolveLocale } from "@formatjs/intl-localematcher";
|
|
2
2
|
import { BigDecimal } from "@formatjs/bigdecimal";
|
|
3
3
|
// node_modules/.aspect_rules_js/@formatjs_generated+cldr.number@0.0.0/node_modules/@formatjs_generated/cldr.number/numbering-systems.js
|
|
4
4
|
const numberingSystemNames = [
|
|
@@ -102,23 +102,33 @@ const numberingSystemNames = [
|
|
|
102
102
|
];
|
|
103
103
|
// packages/ecma402-abstract/IsUnicodeLocaleIdentifierType.js
|
|
104
104
|
const typeApply = Reflect.apply;
|
|
105
|
-
const
|
|
106
|
-
const typePattern = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*(?![\s\S])/i;
|
|
105
|
+
const charCodeAt = String.prototype.charCodeAt;
|
|
107
106
|
/** Tests the Unicode locale identifier `type` grammar, not locale support. */
|
|
108
107
|
function IsUnicodeLocaleIdentifierType(value) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
108
|
+
let length = 0;
|
|
109
|
+
for (let index = 0; index < value.length; index++) {
|
|
110
|
+
const code = typeApply(charCodeAt, value, [index]);
|
|
111
|
+
if (code === 45) {
|
|
112
|
+
if (length < 3) return false;
|
|
113
|
+
length = 0;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const letter = code | 32;
|
|
117
|
+
if (!(letter >= 97 && letter <= 122) && !(code >= 48 && code <= 57)) return false;
|
|
118
|
+
if (++length > 8) return false;
|
|
119
|
+
}
|
|
120
|
+
return length >= 3;
|
|
117
121
|
}
|
|
118
122
|
// packages/ecma262-abstract/intrinsics.js
|
|
119
123
|
const floor = Math.floor;
|
|
124
|
+
const numberFrom = Number;
|
|
120
125
|
const bigIntFrom = BigInt;
|
|
121
126
|
const objectFrom = Object;
|
|
127
|
+
const objectCreate = Object.create;
|
|
128
|
+
function createFromConstructor(newTarget, defaultPrototype) {
|
|
129
|
+
const prototype = newTarget.prototype;
|
|
130
|
+
return objectCreate(objectFrom(prototype) === prototype ? prototype : defaultPrototype);
|
|
131
|
+
}
|
|
122
132
|
const mathAbs = Math.abs;
|
|
123
133
|
const numberIsInteger = Number.isInteger;
|
|
124
134
|
const numberIsFinite = Number.isFinite;
|
|
@@ -144,64 +154,42 @@ function setDataProperty(target, key, value) {
|
|
|
144
154
|
configurable: true
|
|
145
155
|
});
|
|
146
156
|
}
|
|
147
|
-
// packages/ecma262-abstract/ToObject.js
|
|
148
|
-
/**
|
|
149
|
-
* https://tc39.es/ecma262/#sec-toobject
|
|
150
|
-
*/
|
|
151
|
-
function ToObject(arg) {
|
|
152
|
-
if (arg === void 0 || arg === null) throw new TypeErrorConstructor$1("undefined/null cannot be converted to object");
|
|
153
|
-
return objectFrom(arg);
|
|
154
|
-
}
|
|
155
157
|
// packages/ecma402-abstract/CanonicalizeLocaleList.js
|
|
156
158
|
let canonicalIntl = globalThis.Intl;
|
|
157
159
|
const canonicalDescriptor = Object.getOwnPropertyDescriptor;
|
|
158
160
|
const canonicalApply = Reflect.apply;
|
|
161
|
+
const providerKey = Symbol.for("@formatjs/intlCanonicalizeLocaleList");
|
|
159
162
|
function ownCanonicalProvider() {
|
|
160
163
|
const descriptor = canonicalIntl && canonicalDescriptor(canonicalIntl, "getCanonicalLocales");
|
|
161
164
|
return (descriptor && canonicalDescriptor(descriptor, "value"))?.value;
|
|
162
165
|
}
|
|
163
166
|
let canonicalProvider = ownCanonicalProvider();
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
function registeredCanonicalProvider() {
|
|
168
|
+
try {
|
|
169
|
+
const descriptor = canonicalIntl && canonicalDescriptor(canonicalIntl, providerKey);
|
|
170
|
+
return descriptor && canonicalDescriptor(descriptor, "value")?.value;
|
|
171
|
+
} catch {}
|
|
172
|
+
}
|
|
168
173
|
function CanonicalizeLocaleList(locales) {
|
|
169
174
|
if (canonicalIntl === void 0) canonicalIntl = globalThis.Intl;
|
|
170
|
-
const
|
|
171
|
-
if (typeof
|
|
175
|
+
const registered = registeredCanonicalProvider();
|
|
176
|
+
if (typeof registered === "function") return canonicalApply(registered, canonicalIntl, [locales]);
|
|
177
|
+
if (typeof canonicalProvider !== "function") canonicalProvider = ownCanonicalProvider();
|
|
172
178
|
return canonicalApply(canonicalProvider, canonicalIntl, [locales]);
|
|
173
179
|
}
|
|
174
180
|
// packages/ecma402-abstract/DefaultNumberOption.js
|
|
175
|
-
/**
|
|
176
|
-
* ECMA-402 §9.2.13 DefaultNumberOption, step 2.
|
|
177
|
-
* https://tc39.es/ecma402/#sec-defaultnumberoption
|
|
178
|
-
* https://github.com/tc39/ecma402/blob/b1c961988b9a07894b1dc3dc2b5626ea48387d61/spec/negotiation.html#L437
|
|
179
|
-
* @param val
|
|
180
|
-
* @param min
|
|
181
|
-
* @param max
|
|
182
|
-
* @param fallback
|
|
183
|
-
*/
|
|
184
181
|
function DefaultNumberOption(inputVal, min, max, fallback) {
|
|
185
182
|
if (inputVal === void 0) return fallback;
|
|
186
183
|
const val = +inputVal;
|
|
187
|
-
if (val
|
|
188
|
-
return floor(val);
|
|
184
|
+
if (!numberIsFinite(val) || val < min || val > max) throw new RangeErrorConstructor(`${val} is outside of range [${min}, ${max}]`);
|
|
185
|
+
return val === 0 ? 0 : floor(val);
|
|
189
186
|
}
|
|
190
187
|
// packages/ecma402-abstract/GetNumberOption.js
|
|
191
|
-
/**
|
|
192
|
-
* https://tc39.es/ecma402/#sec-getnumberoption
|
|
193
|
-
* @param options
|
|
194
|
-
* @param property
|
|
195
|
-
* @param min
|
|
196
|
-
* @param max
|
|
197
|
-
* @param fallback
|
|
198
|
-
*/
|
|
199
188
|
function GetNumberOption(options, property, minimum, maximum, fallback) {
|
|
200
189
|
const val = options[property];
|
|
201
190
|
return DefaultNumberOption(val, minimum, maximum, fallback);
|
|
202
191
|
}
|
|
203
192
|
// packages/ecma262-abstract/IsObject.js
|
|
204
|
-
/** Includes browser host objects such as document.all. */
|
|
205
193
|
function IsObject(value) {
|
|
206
194
|
return value !== null && (typeof value === "object" || typeof value === "function" || typeof value === "undefined" && value !== void 0);
|
|
207
195
|
}
|
|
@@ -231,28 +219,49 @@ function GetOption(opts, prop, type, values, fallback) {
|
|
|
231
219
|
let value = opts[prop];
|
|
232
220
|
if (value !== void 0) {
|
|
233
221
|
if (type !== "boolean" && type !== "string") throw new TypeErrorConstructor$1("invalid type");
|
|
234
|
-
if (type === "boolean") value =
|
|
222
|
+
if (type === "boolean") value = !!value;
|
|
235
223
|
if (type === "string") value = ToString(value);
|
|
236
|
-
if (values
|
|
224
|
+
if (values?.length && !arraySome(values, (val) => val === value)) throw new RangeErrorConstructor(`${value} is not within ${optionApply(optionJoin, values, [", "])}`);
|
|
237
225
|
return value;
|
|
238
226
|
}
|
|
239
227
|
return fallback;
|
|
240
228
|
}
|
|
241
|
-
// packages/ecma402-abstract/
|
|
229
|
+
// packages/ecma402-abstract/GetOptionsObject.js
|
|
230
|
+
const createObject$2 = Object.create;
|
|
242
231
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* @param requestedLocales
|
|
232
|
+
* ECMA-262 §7.3.36 GetOptionsObject, steps 1–3.
|
|
233
|
+
* https://tc39.es/ecma262/#sec-getoptionsobject
|
|
246
234
|
* @param options
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
function GetOptionsObject(options) {
|
|
238
|
+
if (options === void 0) return createObject$2(null);
|
|
239
|
+
if (IsObject(options)) return options;
|
|
240
|
+
throw new TypeErrorConstructor$1("Options must be an object");
|
|
241
|
+
}
|
|
242
|
+
// packages/ecma262-abstract/ToObject.js
|
|
243
|
+
/**
|
|
244
|
+
* https://tc39.es/ecma262/#sec-toobject
|
|
247
245
|
*/
|
|
246
|
+
function ToObject(arg) {
|
|
247
|
+
if (arg === void 0 || arg === null) throw new TypeErrorConstructor$1("undefined/null cannot be converted to object");
|
|
248
|
+
return objectFrom(arg);
|
|
249
|
+
}
|
|
250
|
+
// packages/ecma402-abstract/CoerceOptionsToObject.js
|
|
251
|
+
const createObject$1 = Object.create;
|
|
252
|
+
/**
|
|
253
|
+
* https://tc39.es/ecma402/#sec-coerceoptionstoobject
|
|
254
|
+
* @param options
|
|
255
|
+
* @returns
|
|
256
|
+
*/
|
|
257
|
+
function CoerceOptionsToObject(options) {
|
|
258
|
+
if (options === void 0) return createObject$1(null);
|
|
259
|
+
return ToObject(options);
|
|
260
|
+
}
|
|
261
|
+
// packages/ecma402-abstract/SupportedLocales.js
|
|
248
262
|
function SupportedLocales(availableLocales, requestedLocales, options) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
options = ToObject(options);
|
|
252
|
-
matcher = GetOption(options, "localeMatcher", "string", ["lookup", "best fit"], "best fit");
|
|
253
|
-
}
|
|
254
|
-
if (matcher === "best fit") return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
|
|
255
|
-
return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
|
|
263
|
+
const matcher = GetOption(CoerceOptionsToObject(options), "localeMatcher", "string", ["lookup", "best fit"], "best fit");
|
|
264
|
+
return FilterLocales(availableLocales, requestedLocales, matcher, true);
|
|
256
265
|
}
|
|
257
266
|
// node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
|
|
258
267
|
const apply$2 = Reflect.apply;
|
|
@@ -339,7 +348,9 @@ const strategies = {
|
|
|
339
348
|
variadic: strategyVariadic,
|
|
340
349
|
monadic: strategyMonadic
|
|
341
350
|
};
|
|
342
|
-
|
|
351
|
+
String.prototype.repeat;
|
|
352
|
+
Array.from;
|
|
353
|
+
Array.prototype.join;
|
|
343
354
|
function defineProperty(target, name, { value }) {
|
|
344
355
|
Object.defineProperty(target, name, {
|
|
345
356
|
configurable: true,
|
|
@@ -349,12 +360,21 @@ function defineProperty(target, name, { value }) {
|
|
|
349
360
|
});
|
|
350
361
|
}
|
|
351
362
|
function ensureIntl() {
|
|
352
|
-
if (typeof Intl === "undefined")
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
363
|
+
if (typeof Intl === "undefined") {
|
|
364
|
+
const intl = {};
|
|
365
|
+
if (typeof Symbol !== "undefined") Object.defineProperty(intl, Symbol.toStringTag, {
|
|
366
|
+
value: "Intl",
|
|
367
|
+
writable: false,
|
|
368
|
+
enumerable: false,
|
|
369
|
+
configurable: true
|
|
370
|
+
});
|
|
371
|
+
Object.defineProperty(globalThis, "Intl", {
|
|
372
|
+
configurable: true,
|
|
373
|
+
enumerable: false,
|
|
374
|
+
writable: true,
|
|
375
|
+
value: intl
|
|
376
|
+
});
|
|
377
|
+
}
|
|
358
378
|
if (providerIntl === void 0) providerIntl = Intl;
|
|
359
379
|
return Intl;
|
|
360
380
|
}
|
|
@@ -362,7 +382,6 @@ function invariant(condition, message, Err = ErrorConstructor) {
|
|
|
362
382
|
if (!condition) throw new Err(message);
|
|
363
383
|
}
|
|
364
384
|
memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
|
|
365
|
-
memoize((...args) => new Intl.PluralRules(...args), { strategy: strategies.variadic });
|
|
366
385
|
memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic });
|
|
367
386
|
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
368
387
|
const formatterMemoizeOptions = {
|
|
@@ -374,58 +393,77 @@ function ownIntlProvider(name) {
|
|
|
374
393
|
const descriptor = providerIntl && getOwnPropertyDescriptor(providerIntl, name);
|
|
375
394
|
return (descriptor && getOwnPropertyDescriptor(descriptor, "value"))?.value;
|
|
376
395
|
}
|
|
377
|
-
let
|
|
378
|
-
let
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
396
|
+
let numberFormatIntrinsic = ownIntlProvider("NumberFormat");
|
|
397
|
+
let listFormatIntrinsic = ownIntlProvider("ListFormat");
|
|
398
|
+
let pluralRulesProvider = ownIntlProvider("PluralRules");
|
|
399
|
+
const formatterIntrinsicKeys = {
|
|
400
|
+
NumberFormat: Symbol.for("@formatjs/intlNumberFormat"),
|
|
401
|
+
ListFormat: Symbol.for("@formatjs/intlListFormat"),
|
|
402
|
+
PluralRules: Symbol.for("@formatjs/intlPluralRules")
|
|
403
|
+
};
|
|
404
|
+
function getNumberFormatIntrinsic() {
|
|
405
|
+
if (providerIntl === void 0) providerIntl = globalThis.Intl;
|
|
406
|
+
const registered = ownIntlProvider(formatterIntrinsicKeys.NumberFormat);
|
|
407
|
+
if (typeof registered === "function") return registered;
|
|
408
|
+
if (typeof numberFormatIntrinsic !== "function") numberFormatIntrinsic = ownIntlProvider("NumberFormat");
|
|
409
|
+
return numberFormatIntrinsic;
|
|
383
410
|
}
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
return
|
|
411
|
+
function getListFormatIntrinsic() {
|
|
412
|
+
if (providerIntl === void 0) providerIntl = globalThis.Intl;
|
|
413
|
+
const registered = ownIntlProvider(formatterIntrinsicKeys.ListFormat);
|
|
414
|
+
if (typeof registered === "function") return registered;
|
|
415
|
+
if (typeof listFormatIntrinsic !== "function") listFormatIntrinsic = ownIntlProvider("ListFormat");
|
|
416
|
+
return listFormatIntrinsic;
|
|
388
417
|
}
|
|
389
418
|
const getFormatterPrototype = Object.getPrototypeOf;
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
const
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
419
|
+
function formatterMethodLookup(name) {
|
|
420
|
+
const methods = /* @__PURE__ */ new WeakMap();
|
|
421
|
+
const owners = /* @__PURE__ */ new WeakMap();
|
|
422
|
+
const getMethod = methods.get.bind(methods);
|
|
423
|
+
const setMethod = methods.set.bind(methods);
|
|
424
|
+
const getOwner = owners.get.bind(owners);
|
|
425
|
+
const setOwner = owners.set.bind(owners);
|
|
426
|
+
return (Constructor) => {
|
|
427
|
+
const cached = getMethod(Constructor);
|
|
428
|
+
if (cached) return cached;
|
|
429
|
+
let prototype = getOwnPropertyDescriptor(Constructor, "prototype")?.value;
|
|
430
|
+
while (prototype != null) {
|
|
431
|
+
const inherited = getOwner(prototype);
|
|
432
|
+
if (inherited) {
|
|
433
|
+
setMethod(Constructor, inherited);
|
|
434
|
+
return inherited;
|
|
435
|
+
}
|
|
436
|
+
const descriptor = getOwnPropertyDescriptor(prototype, name);
|
|
437
|
+
const value = descriptor && getOwnPropertyDescriptor(descriptor, "value");
|
|
438
|
+
if (value && typeof value.value === "function") {
|
|
439
|
+
const method = value.value;
|
|
440
|
+
setMethod(Constructor, method);
|
|
441
|
+
setOwner(prototype, method);
|
|
442
|
+
return method;
|
|
443
|
+
}
|
|
444
|
+
prototype = getFormatterPrototype(prototype);
|
|
412
445
|
}
|
|
413
|
-
|
|
414
|
-
}
|
|
446
|
+
};
|
|
415
447
|
}
|
|
448
|
+
const findFormatterPartsMethod = formatterMethodLookup("formatToParts");
|
|
449
|
+
const findPluralRulesSelectMethod = formatterMethodLookup("select");
|
|
416
450
|
function getFormatterPartsMethod(Constructor) {
|
|
417
451
|
const method = findFormatterPartsMethod(Constructor);
|
|
418
452
|
if (!method) throw new TypeErrorConstructor$1("Missing supplied formatter parts method");
|
|
419
453
|
return method;
|
|
420
454
|
}
|
|
421
|
-
if (typeof
|
|
422
|
-
if (typeof
|
|
455
|
+
if (typeof numberFormatIntrinsic === "function") findFormatterPartsMethod(numberFormatIntrinsic);
|
|
456
|
+
if (typeof listFormatIntrinsic === "function") findFormatterPartsMethod(listFormatIntrinsic);
|
|
457
|
+
if (typeof pluralRulesProvider === "function") findPluralRulesSelectMethod(pluralRulesProvider);
|
|
423
458
|
const numberFormatMemoizers = /* @__PURE__ */ new WeakMap();
|
|
424
459
|
const getNumberFormatMemoizer = numberFormatMemoizers.get.bind(numberFormatMemoizers);
|
|
425
460
|
const setNumberFormatMemoizer = numberFormatMemoizers.set.bind(numberFormatMemoizers);
|
|
426
461
|
const listFormatMemoizers = /* @__PURE__ */ new WeakMap();
|
|
427
462
|
const getListFormatMemoizer = listFormatMemoizers.get.bind(listFormatMemoizers);
|
|
428
463
|
const setListFormatMemoizer = listFormatMemoizers.set.bind(listFormatMemoizers);
|
|
464
|
+
const pluralRulesMemoizers = /* @__PURE__ */ new WeakMap();
|
|
465
|
+
pluralRulesMemoizers.get.bind(pluralRulesMemoizers);
|
|
466
|
+
pluralRulesMemoizers.set.bind(pluralRulesMemoizers);
|
|
429
467
|
function createMemoizedNumberFormatForConstructor(Constructor) {
|
|
430
468
|
let factory = getNumberFormatMemoizer(Constructor);
|
|
431
469
|
if (!factory) {
|
|
@@ -444,7 +482,8 @@ function createMemoizedListFormatForConstructor(Constructor) {
|
|
|
444
482
|
}
|
|
445
483
|
// packages/ecma402-abstract/DurationFormat/GetDurationUnitOptions.js
|
|
446
484
|
function GetDurationUnitOptions(unit, options, baseStyle, stylesList, digitalBase, prevStyle, twoDigitHours = false) {
|
|
447
|
-
|
|
485
|
+
const unitOptions = options;
|
|
486
|
+
let style = GetOption(unitOptions, unit, "string", stylesList, void 0);
|
|
448
487
|
let displayDefault = "always";
|
|
449
488
|
if (style === void 0) {
|
|
450
489
|
if (baseStyle === "digital") {
|
|
@@ -462,7 +501,7 @@ function GetDurationUnitOptions(unit, options, baseStyle, stylesList, digitalBas
|
|
|
462
501
|
style = "fractional";
|
|
463
502
|
displayDefault = "auto";
|
|
464
503
|
}
|
|
465
|
-
const display = GetOption(
|
|
504
|
+
const display = GetOption(unitOptions, `${unit}Display`, "string", ["always", "auto"], displayDefault);
|
|
466
505
|
if (display === "always" && style === "fractional") throw new RangeErrorConstructor("Fractional units cannot use always display");
|
|
467
506
|
if (prevStyle === "fractional" && style !== "fractional") throw new RangeErrorConstructor("Fractional units must be followed by fractional units");
|
|
468
507
|
if ((prevStyle === "numeric" || prevStyle === "2-digit") && style !== "fractional" && style !== "numeric" && style !== "2-digit") throw new RangeErrorConstructor("Can't mix numeric and non-numeric styles");
|
|
@@ -551,6 +590,11 @@ const internalSlotMap = /* @__PURE__ */ new WeakMap();
|
|
|
551
590
|
const getSlots = internalSlotMap.get.bind(internalSlotMap);
|
|
552
591
|
const setSlots = internalSlotMap.set.bind(internalSlotMap);
|
|
553
592
|
const createSlots = Object.create;
|
|
593
|
+
function requireInternalSlots(x) {
|
|
594
|
+
const slots = getSlots(x);
|
|
595
|
+
if (!slots?.initializedDurationFormat) throw new TypeErrorConstructor$1("Incompatible Intl.DurationFormat receiver");
|
|
596
|
+
return slots;
|
|
597
|
+
}
|
|
554
598
|
function getInternalSlots(x) {
|
|
555
599
|
let internalSlots = getSlots(x);
|
|
556
600
|
if (!internalSlots) {
|
|
@@ -567,8 +611,8 @@ const formatterProviders = /* @__PURE__ */ new WeakMap();
|
|
|
567
611
|
const getFormatterProviders = formatterProviders.get.bind(formatterProviders);
|
|
568
612
|
const setFormatterProviders = formatterProviders.set.bind(formatterProviders);
|
|
569
613
|
function initializeDurationFormatProviders(df) {
|
|
570
|
-
const NumberFormat =
|
|
571
|
-
const ListFormat =
|
|
614
|
+
const NumberFormat = getNumberFormatIntrinsic();
|
|
615
|
+
const ListFormat = getListFormatIntrinsic();
|
|
572
616
|
setFormatterProviders(df, {
|
|
573
617
|
numberFormat: createMemoizedNumberFormatForConstructor(NumberFormat),
|
|
574
618
|
listFormat: createMemoizedListFormatForConstructor(ListFormat),
|
|
@@ -584,11 +628,6 @@ function PartitionDurationFormatPattern(df, duration) {
|
|
|
584
628
|
const negative = arraySome(TABLE_2, (row) => duration[row.valueField] < 0);
|
|
585
629
|
const internalSlots = getInternalSlots(df);
|
|
586
630
|
const providers = getFormatterProviders(df);
|
|
587
|
-
let dataLocale = internalSlots.dataLocale;
|
|
588
|
-
const dataLocaleData = DurationFormat.localeData[dataLocale];
|
|
589
|
-
if (!dataLocaleData) throw new TypeError("Invalid locale");
|
|
590
|
-
const numberingSystem = internalSlots.numberingSystem;
|
|
591
|
-
const separator = dataLocaleData.digitalFormat[numberingSystem] ?? dataLocaleData.digitalFormat.default;
|
|
592
631
|
for (let i = 0; i < TABLE_2.length && !done; i++) {
|
|
593
632
|
const row = TABLE_2[i];
|
|
594
633
|
let value = new BigDecimal(bigIntFrom(duration[row.valueField]));
|
|
@@ -601,7 +640,7 @@ function PartitionDurationFormatPattern(df, duration) {
|
|
|
601
640
|
if (unit === "seconds") nextStyle = internalSlots.milliseconds;
|
|
602
641
|
else if (unit === "milliseconds") nextStyle = internalSlots.microseconds;
|
|
603
642
|
else nextStyle = internalSlots.nanoseconds;
|
|
604
|
-
if (nextStyle === "
|
|
643
|
+
if (nextStyle === "fractional") {
|
|
605
644
|
if (unit === "seconds") value = value.plus(new BigDecimal(bigIntFrom(duration.milliseconds)).div(bigIntFrom(1e3))).plus(new BigDecimal(bigIntFrom(duration.microseconds)).div(bigIntFrom(1e6))).plus(new BigDecimal(bigIntFrom(duration.nanoseconds)).div(bigIntFrom(1e9)));
|
|
606
645
|
else if (unit === "milliseconds") value = value.plus(new BigDecimal(bigIntFrom(duration.microseconds)).div(bigIntFrom(1e3))).plus(new BigDecimal(bigIntFrom(duration.nanoseconds)).div(bigIntFrom(1e6)));
|
|
607
646
|
else value = value.plus(new BigDecimal(bigIntFrom(duration.nanoseconds)).div(bigIntFrom(1e3)));
|
|
@@ -637,7 +676,8 @@ function PartitionDurationFormatPattern(df, duration) {
|
|
|
637
676
|
list = result[result.length - 1];
|
|
638
677
|
setDataProperty(list, `${list.length}`, {
|
|
639
678
|
type: "literal",
|
|
640
|
-
value:
|
|
679
|
+
value: unit === "minutes" ? internalSlots.hourMinuteSeparator : internalSlots.minuteSecondSeparator,
|
|
680
|
+
unit: void 0
|
|
641
681
|
});
|
|
642
682
|
}
|
|
643
683
|
let parts = apply$1(providers.numberFormatToParts, nf, [value.isZero() && value.isNegative() ? -0 : value]);
|
|
@@ -692,7 +732,8 @@ function PartitionDurationFormatPattern(df, duration) {
|
|
|
692
732
|
invariant(type === "literal", "Type must be literal");
|
|
693
733
|
setDataProperty(flattened, `${flattened.length}`, {
|
|
694
734
|
type: "literal",
|
|
695
|
-
value
|
|
735
|
+
value,
|
|
736
|
+
unit: void 0
|
|
696
737
|
});
|
|
697
738
|
}
|
|
698
739
|
}
|
|
@@ -740,12 +781,10 @@ function IsValidDurationRecord(record) {
|
|
|
740
781
|
return normalizedNanoseconds > -limit && normalizedNanoseconds < limit;
|
|
741
782
|
}
|
|
742
783
|
// packages/ecma262-abstract/ToNumber.js
|
|
743
|
-
/** ECMA-262 §7.1.4, via §13.5.4.1 step 2. */
|
|
744
784
|
function ToNumber(arg) {
|
|
745
785
|
return +arg;
|
|
746
786
|
}
|
|
747
787
|
// packages/ecma402-abstract/DurationFormat/ToIntegerIfIntegral.js
|
|
748
|
-
/** ECMA-402 §13.5.2 steps 1–3. */
|
|
749
788
|
function ToIntegerIfIntegral(arg) {
|
|
750
789
|
const number = ToNumber(arg);
|
|
751
790
|
if (!numberIsInteger(number)) throw new RangeErrorConstructor("Duration field is not an integer");
|
|
@@ -891,6 +930,7 @@ const TIME_SEPARATORS = {
|
|
|
891
930
|
"az-Cyrl": { "nu": ["latn"] },
|
|
892
931
|
"az-Latn": { "nu": ["latn"] },
|
|
893
932
|
"ba": { "nu": ["latn"] },
|
|
933
|
+
"bal": { "nu": ["latn"] },
|
|
894
934
|
"bal-Latn": { "nu": ["latn"] },
|
|
895
935
|
"bas": { "nu": ["latn"] },
|
|
896
936
|
"be": { "nu": ["latn"] },
|
|
@@ -914,6 +954,7 @@ const TIME_SEPARATORS = {
|
|
|
914
954
|
"bua": { "nu": ["latn"] },
|
|
915
955
|
"ca": { "nu": ["latn"] },
|
|
916
956
|
"ca-AD": { "nu": ["latn"] },
|
|
957
|
+
"ca-ES": { "nu": ["latn"] },
|
|
917
958
|
"ca-ES-valencia": { "nu": ["latn"] },
|
|
918
959
|
"ca-FR": { "nu": ["latn"] },
|
|
919
960
|
"ca-IT": { "nu": ["latn"] },
|
|
@@ -1135,6 +1176,13 @@ const TIME_SEPARATORS = {
|
|
|
1135
1176
|
"ff-Adlm-NG": { "nu": ["adlm"] },
|
|
1136
1177
|
"ff-Adlm-SL": { "nu": ["adlm"] },
|
|
1137
1178
|
"ff-Adlm-SN": { "nu": ["adlm"] },
|
|
1179
|
+
"ff-BF": { "nu": ["latn"] },
|
|
1180
|
+
"ff-CM": { "nu": ["latn"] },
|
|
1181
|
+
"ff-GH": { "nu": ["latn"] },
|
|
1182
|
+
"ff-GM": { "nu": ["latn"] },
|
|
1183
|
+
"ff-GN": { "nu": ["latn"] },
|
|
1184
|
+
"ff-GW": { "nu": ["latn"] },
|
|
1185
|
+
"ff-LR": { "nu": ["latn"] },
|
|
1138
1186
|
"ff-Latn": { "nu": ["latn"] },
|
|
1139
1187
|
"ff-Latn-BF": { "nu": ["latn"] },
|
|
1140
1188
|
"ff-Latn-CM": { "nu": ["latn"] },
|
|
@@ -1147,6 +1195,11 @@ const TIME_SEPARATORS = {
|
|
|
1147
1195
|
"ff-Latn-NE": { "nu": ["latn"] },
|
|
1148
1196
|
"ff-Latn-NG": { "nu": ["latn"] },
|
|
1149
1197
|
"ff-Latn-SL": { "nu": ["latn"] },
|
|
1198
|
+
"ff-MR": { "nu": ["latn"] },
|
|
1199
|
+
"ff-NE": { "nu": ["latn"] },
|
|
1200
|
+
"ff-NG": { "nu": ["latn"] },
|
|
1201
|
+
"ff-SL": { "nu": ["latn"] },
|
|
1202
|
+
"ff-SN": { "nu": ["adlm"] },
|
|
1150
1203
|
"fi": {
|
|
1151
1204
|
"nu": ["latn"],
|
|
1152
1205
|
"separator": { "latn": "." }
|
|
@@ -1275,9 +1328,11 @@ const TIME_SEPARATORS = {
|
|
|
1275
1328
|
"ksf": { "nu": ["latn"] },
|
|
1276
1329
|
"ksh": { "nu": ["latn"] },
|
|
1277
1330
|
"ku": { "nu": ["latn"] },
|
|
1331
|
+
"ku-IQ": { "nu": ["latn"] },
|
|
1278
1332
|
"ku-Latn": { "nu": ["latn"] },
|
|
1279
1333
|
"ku-Latn-IQ": { "nu": ["latn"] },
|
|
1280
1334
|
"ku-Latn-SY": { "nu": ["latn"] },
|
|
1335
|
+
"ku-SY": { "nu": ["latn"] },
|
|
1281
1336
|
"ku-TR": { "nu": ["latn"] },
|
|
1282
1337
|
"kw": { "nu": ["latn"] },
|
|
1283
1338
|
"kxv": { "nu": ["latn"] },
|
|
@@ -1438,6 +1493,7 @@ const TIME_SEPARATORS = {
|
|
|
1438
1493
|
"sq-MK": { "nu": ["latn"] },
|
|
1439
1494
|
"sq-XK": { "nu": ["latn"] },
|
|
1440
1495
|
"sr": { "nu": ["latn"] },
|
|
1496
|
+
"sr-BA": { "nu": ["latn"] },
|
|
1441
1497
|
"sr-Cyrl": { "nu": ["latn"] },
|
|
1442
1498
|
"sr-Cyrl-BA": { "nu": ["latn"] },
|
|
1443
1499
|
"sr-Cyrl-ME": { "nu": ["latn"] },
|
|
@@ -1446,6 +1502,8 @@ const TIME_SEPARATORS = {
|
|
|
1446
1502
|
"sr-Latn-BA": { "nu": ["latn"] },
|
|
1447
1503
|
"sr-Latn-ME": { "nu": ["latn"] },
|
|
1448
1504
|
"sr-Latn-XK": { "nu": ["latn"] },
|
|
1505
|
+
"sr-ME": { "nu": ["latn"] },
|
|
1506
|
+
"sr-XK": { "nu": ["latn"] },
|
|
1449
1507
|
"st": { "nu": ["latn"] },
|
|
1450
1508
|
"st-LS": { "nu": ["latn"] },
|
|
1451
1509
|
"su": {
|
|
@@ -1456,6 +1514,7 @@ const TIME_SEPARATORS = {
|
|
|
1456
1514
|
"nu": ["latn"],
|
|
1457
1515
|
"separator": { "latn": "." }
|
|
1458
1516
|
},
|
|
1517
|
+
"suz": { "nu": ["latn"] },
|
|
1459
1518
|
"suz-Sunu": { "nu": ["latn"] },
|
|
1460
1519
|
"sv": { "nu": ["latn"] },
|
|
1461
1520
|
"sv-AX": { "nu": ["latn"] },
|
|
@@ -1530,13 +1589,16 @@ const TIME_SEPARATORS = {
|
|
|
1530
1589
|
"yrl-CO": { "nu": ["latn"] },
|
|
1531
1590
|
"yrl-VE": { "nu": ["latn"] },
|
|
1532
1591
|
"yue": { "nu": ["latn"] },
|
|
1592
|
+
"yue-CN": { "nu": ["latn"] },
|
|
1533
1593
|
"yue-Hans": { "nu": ["latn"] },
|
|
1534
1594
|
"yue-Hant": { "nu": ["latn"] },
|
|
1535
1595
|
"yue-Hant-CN": { "nu": ["latn"] },
|
|
1536
1596
|
"yue-Hant-MO": { "nu": ["latn"] },
|
|
1597
|
+
"yue-MO": { "nu": ["latn"] },
|
|
1537
1598
|
"za": { "nu": ["latn"] },
|
|
1538
1599
|
"zgh": { "nu": ["latn"] },
|
|
1539
1600
|
"zh": { "nu": ["latn"] },
|
|
1601
|
+
"zh-HK": { "nu": ["latn"] },
|
|
1540
1602
|
"zh-Hans": { "nu": ["latn"] },
|
|
1541
1603
|
"zh-Hans-HK": { "nu": ["latn"] },
|
|
1542
1604
|
"zh-Hans-MO": { "nu": ["latn"] },
|
|
@@ -1546,14 +1608,22 @@ const TIME_SEPARATORS = {
|
|
|
1546
1608
|
"zh-Hant-HK": { "nu": ["latn"] },
|
|
1547
1609
|
"zh-Hant-MO": { "nu": ["latn"] },
|
|
1548
1610
|
"zh-Hant-MY": { "nu": ["latn"] },
|
|
1611
|
+
"zh-MO": { "nu": ["latn"] },
|
|
1612
|
+
"zh-MY": { "nu": ["latn"] },
|
|
1613
|
+
"zh-SG": { "nu": ["latn"] },
|
|
1549
1614
|
"zu": { "nu": ["latn"] }
|
|
1550
1615
|
}
|
|
1551
1616
|
};
|
|
1552
1617
|
// packages/intl-durationformat/core.ts
|
|
1618
|
+
let defaultLocale = "en";
|
|
1619
|
+
function getDefaultLocale() {
|
|
1620
|
+
return defaultLocale;
|
|
1621
|
+
}
|
|
1553
1622
|
const numberingSystemsByConstructor = /* @__PURE__ */ new WeakMap();
|
|
1554
1623
|
const getNumberingSystems = numberingSystemsByConstructor.get.bind(numberingSystemsByConstructor);
|
|
1555
1624
|
const setNumberingSystems = numberingSystemsByConstructor.set.bind(numberingSystemsByConstructor);
|
|
1556
1625
|
const createObject = Object.create;
|
|
1626
|
+
const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
|
|
1557
1627
|
const providerApply = Reflect.apply;
|
|
1558
1628
|
const providerDescriptor = Object.getOwnPropertyDescriptor;
|
|
1559
1629
|
const providerPrototype = Object.getPrototypeOf;
|
|
@@ -1575,7 +1645,7 @@ function numberFormatResolvedOptions(Constructor) {
|
|
|
1575
1645
|
prototype = providerPrototype(prototype);
|
|
1576
1646
|
}
|
|
1577
1647
|
}
|
|
1578
|
-
const initialNumberFormat =
|
|
1648
|
+
const initialNumberFormat = getNumberFormatIntrinsic();
|
|
1579
1649
|
if (typeof initialNumberFormat === "function") numberFormatResolvedOptions(initialNumberFormat);
|
|
1580
1650
|
const NumberingSet = Set;
|
|
1581
1651
|
const numberingAdd = Set.prototype.add;
|
|
@@ -1594,7 +1664,7 @@ function numberingUnion(first, second) {
|
|
|
1594
1664
|
}
|
|
1595
1665
|
}
|
|
1596
1666
|
function supportedNumberingSystems() {
|
|
1597
|
-
const NumberFormat =
|
|
1667
|
+
const NumberFormat = getNumberFormatIntrinsic();
|
|
1598
1668
|
let systems = getNumberingSystems(NumberFormat);
|
|
1599
1669
|
if (!systems) {
|
|
1600
1670
|
systems = [];
|
|
@@ -1762,27 +1832,33 @@ const TABLE_3 = [
|
|
|
1762
1832
|
* DurationFormat provides locale-sensitive duration formatting
|
|
1763
1833
|
* Implements the Intl.DurationFormat API from the TC39 proposal
|
|
1764
1834
|
*/
|
|
1765
|
-
var DurationFormat = class DurationFormat {
|
|
1835
|
+
var DurationFormat = class DurationFormat extends null {
|
|
1766
1836
|
static __addTemporalNamespace(namespace) {
|
|
1767
1837
|
registerTemporalDurationNamespace(namespace);
|
|
1768
1838
|
}
|
|
1769
1839
|
constructor(locales, options) {
|
|
1770
|
-
|
|
1840
|
+
const receiver = createFromConstructor(new.target, DurationFormat.prototype);
|
|
1771
1841
|
const requestedLocales = CanonicalizeLocaleList(locales);
|
|
1772
1842
|
const opt = createObject(null);
|
|
1773
|
-
const opts =
|
|
1843
|
+
const opts = GetOptionsObject(options);
|
|
1774
1844
|
const matcher = GetOption(opts, "localeMatcher", "string", ["best fit", "lookup"], "best fit");
|
|
1775
1845
|
const numberingSystem = GetOption(opts, "numberingSystem", "string", void 0, void 0);
|
|
1776
1846
|
if (numberingSystem !== void 0 && !IsUnicodeLocaleIdentifierType(numberingSystem)) throw RangeErrorConstructor(`Invalid numberingSystems: ${numberingSystem}`);
|
|
1777
1847
|
opt.nu = numberingSystem;
|
|
1778
1848
|
opt.localeMatcher = matcher;
|
|
1779
1849
|
const { localeData, availableLocales } = DurationFormat;
|
|
1780
|
-
const r = ResolveLocale(availableLocales, requestedLocales, opt, ["nu"], localeData,
|
|
1850
|
+
const r = ResolveLocale(availableLocales, requestedLocales, opt, ["nu"], localeData, getDefaultLocale, "hostDefaultWithLocaleData");
|
|
1781
1851
|
const locale = r.locale;
|
|
1782
|
-
const internalSlots = getInternalSlots(
|
|
1852
|
+
const internalSlots = getInternalSlots(receiver);
|
|
1783
1853
|
internalSlots.initializedDurationFormat = true;
|
|
1784
1854
|
internalSlots.locale = locale;
|
|
1785
1855
|
internalSlots.numberingSystem = r.nu;
|
|
1856
|
+
internalSlots.dataLocale = r.dataLocale;
|
|
1857
|
+
const digitalFormat = r.localeData?.digitalFormat;
|
|
1858
|
+
invariant(!!digitalFormat, `Invalid locale ${r.dataLocale}`);
|
|
1859
|
+
const separator = hasOwn(digitalFormat, r.nu) ? digitalFormat[r.nu] : digitalFormat.default;
|
|
1860
|
+
internalSlots.hourMinuteSeparator = separator;
|
|
1861
|
+
internalSlots.minuteSecondSeparator = separator;
|
|
1786
1862
|
const style = GetOption(opts, "style", "string", [
|
|
1787
1863
|
"long",
|
|
1788
1864
|
"short",
|
|
@@ -1790,35 +1866,36 @@ var DurationFormat = class DurationFormat {
|
|
|
1790
1866
|
"digital"
|
|
1791
1867
|
], "short");
|
|
1792
1868
|
internalSlots.style = style;
|
|
1793
|
-
internalSlots.dataLocale = r.dataLocale;
|
|
1794
1869
|
let prevStyle = "";
|
|
1870
|
+
const unitStyles = internalSlots;
|
|
1795
1871
|
for (let index = 0; index < TABLE_3.length; index++) {
|
|
1796
1872
|
const { styleSlot, displaySlot, unit, values: valueList, digitalDefault: digitalBase } = TABLE_3[index];
|
|
1797
1873
|
const unitOptions = GetDurationUnitOptions(unit, opts, style, valueList, digitalBase, prevStyle);
|
|
1798
|
-
|
|
1874
|
+
unitStyles[styleSlot] = unitOptions.style;
|
|
1799
1875
|
internalSlots[displaySlot] = unitOptions.display;
|
|
1800
1876
|
if (unit === "hours" || unit === "minutes" || unit === "seconds" || unit === "milliseconds" || unit === "microseconds") prevStyle = unitOptions.style;
|
|
1801
1877
|
}
|
|
1802
1878
|
internalSlots.fractionalDigits = GetNumberOption(opts, "fractionalDigits", 0, 9, void 0);
|
|
1803
|
-
initializeDurationFormatProviders(
|
|
1879
|
+
initializeDurationFormatProviders(receiver);
|
|
1880
|
+
return receiver;
|
|
1804
1881
|
}
|
|
1805
1882
|
resolvedOptions() {
|
|
1806
|
-
|
|
1807
|
-
const internalSlots = getInternalSlots(this);
|
|
1883
|
+
const internalSlots = requireInternalSlots(this);
|
|
1808
1884
|
const ro = {};
|
|
1809
|
-
for (
|
|
1885
|
+
for (let index = 0; index < RESOLVED_OPTIONS_KEYS.length; index++) {
|
|
1886
|
+
const key = RESOLVED_OPTIONS_KEYS[index];
|
|
1810
1887
|
let v = internalSlots[key];
|
|
1811
1888
|
if (key === "fractionalDigits") {
|
|
1812
1889
|
if (v === void 0) continue;
|
|
1813
|
-
v =
|
|
1890
|
+
v = numberFrom(v);
|
|
1814
1891
|
} else if (v === "fractional") v = "numeric";
|
|
1815
1892
|
else invariant(v !== void 0, `Missing internal slot ${key}`);
|
|
1816
|
-
ro
|
|
1893
|
+
setDataProperty(ro, key, v);
|
|
1817
1894
|
}
|
|
1818
1895
|
return ro;
|
|
1819
1896
|
}
|
|
1820
1897
|
formatToParts(duration) {
|
|
1821
|
-
|
|
1898
|
+
requireInternalSlots(this);
|
|
1822
1899
|
const record = ToTemporalDurationRecord(duration);
|
|
1823
1900
|
const parts = PartitionDurationFormatPattern(this, record);
|
|
1824
1901
|
const result = [];
|
|
@@ -1834,7 +1911,7 @@ var DurationFormat = class DurationFormat {
|
|
|
1834
1911
|
return result;
|
|
1835
1912
|
}
|
|
1836
1913
|
format(duration) {
|
|
1837
|
-
|
|
1914
|
+
requireInternalSlots(this);
|
|
1838
1915
|
const record = ToTemporalDurationRecord(duration);
|
|
1839
1916
|
const parts = PartitionDurationFormatPattern(this, record);
|
|
1840
1917
|
let result = "";
|
|
@@ -1844,9 +1921,6 @@ var DurationFormat = class DurationFormat {
|
|
|
1844
1921
|
static supportedLocalesOf(locales, options) {
|
|
1845
1922
|
return SupportedLocales(DurationFormat.availableLocales, CanonicalizeLocaleList(locales), options);
|
|
1846
1923
|
}
|
|
1847
|
-
static {
|
|
1848
|
-
this.__defaultLocale = "en";
|
|
1849
|
-
}
|
|
1850
1924
|
static {
|
|
1851
1925
|
this.availableLocales = /* @__PURE__ */ new Set();
|
|
1852
1926
|
}
|
|
@@ -1867,14 +1941,20 @@ var DurationFormat = class DurationFormat {
|
|
|
1867
1941
|
}, {});
|
|
1868
1942
|
}
|
|
1869
1943
|
static {
|
|
1870
|
-
this.getDefaultLocale =
|
|
1871
|
-
return DurationFormat.__defaultLocale;
|
|
1872
|
-
};
|
|
1944
|
+
this.getDefaultLocale = getDefaultLocale;
|
|
1873
1945
|
}
|
|
1874
1946
|
static {
|
|
1875
1947
|
this.polyfilled = true;
|
|
1876
1948
|
}
|
|
1877
1949
|
};
|
|
1950
|
+
Object.defineProperty(DurationFormat, "__defaultLocale", {
|
|
1951
|
+
configurable: true,
|
|
1952
|
+
enumerable: true,
|
|
1953
|
+
get: getDefaultLocale,
|
|
1954
|
+
set(locale) {
|
|
1955
|
+
defaultLocale = locale;
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1878
1958
|
Object.defineProperty(DurationFormat, "length", {
|
|
1879
1959
|
value: 0,
|
|
1880
1960
|
configurable: true
|
|
@@ -1883,6 +1963,7 @@ Object.defineProperty(DurationFormat.supportedLocalesOf, "length", {
|
|
|
1883
1963
|
value: 1,
|
|
1884
1964
|
configurable: true
|
|
1885
1965
|
});
|
|
1966
|
+
Object.setPrototypeOf(DurationFormat.prototype, Object.prototype);
|
|
1886
1967
|
Object.defineProperty(DurationFormat.prototype, Symbol.toStringTag, {
|
|
1887
1968
|
value: "Intl.DurationFormat",
|
|
1888
1969
|
configurable: true
|