@formatjs/intl-durationformat 0.12.4 → 0.13.0
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 +8 -2
- package/index.js +31 -11
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/polyfill-force.js +31 -11
- package/polyfill-force.js.map +1 -1
- package/polyfill.js +31 -11
- package/polyfill.js.map +1 -1
- package/should-polyfill.d.ts +1 -2
package/package.json
CHANGED
package/polyfill-force.js
CHANGED
|
@@ -115,9 +115,9 @@ function IsCallable(fn) {
|
|
|
115
115
|
function OrdinaryHasInstance(C, O, internalSlots) {
|
|
116
116
|
if (!IsCallable(C)) return false;
|
|
117
117
|
if (internalSlots?.boundTargetFunction) return O instanceof internalSlots?.boundTargetFunction;
|
|
118
|
-
if (typeof O !== "object") return false;
|
|
118
|
+
if (O === null || typeof O !== "object" && typeof O !== "function") return false;
|
|
119
119
|
let P = C.prototype;
|
|
120
|
-
if (typeof P !== "object") throw new TypeError("OrdinaryHasInstance called on an object with an invalid prototype property.");
|
|
120
|
+
if (P === null || typeof P !== "object" && typeof P !== "function") throw new TypeError("OrdinaryHasInstance called on an object with an invalid prototype property.");
|
|
121
121
|
return Object.prototype.isPrototypeOf.call(P, O);
|
|
122
122
|
}
|
|
123
123
|
// packages/ecma262-abstract/ToObject.js
|
|
@@ -616,9 +616,7 @@ function ToDurationRecord(input) {
|
|
|
616
616
|
if (!IsValidDurationRecord(result)) throw new RangeError("Invalid duration format");
|
|
617
617
|
return result;
|
|
618
618
|
}
|
|
619
|
-
// packages/
|
|
620
|
-
const temporalDuration = globalThis.Temporal?.Duration;
|
|
621
|
-
const durationFrom = temporalDuration?.from;
|
|
619
|
+
// packages/ecma402-abstract/DurationFormat/ToTemporalDurationRecord.js
|
|
622
620
|
const fields = [
|
|
623
621
|
"years",
|
|
624
622
|
"months",
|
|
@@ -631,19 +629,38 @@ const fields = [
|
|
|
631
629
|
"microseconds",
|
|
632
630
|
"nanoseconds"
|
|
633
631
|
];
|
|
634
|
-
const
|
|
632
|
+
const apply = Reflect.apply;
|
|
633
|
+
const readers = [];
|
|
634
|
+
function registerTemporalDurationNamespace(namespace) {
|
|
635
|
+
const constructor = namespace?.Duration;
|
|
636
|
+
if (!constructor || readers.some((reader) => reader.constructor === constructor)) return;
|
|
637
|
+
const from = constructor.from, prototype = constructor.prototype;
|
|
638
|
+
if (typeof from !== "function" || prototype === null || typeof prototype !== "object" && typeof prototype !== "function") return;
|
|
639
|
+
const getters = fields.map((field) => Object.getOwnPropertyDescriptor(prototype, field)?.get);
|
|
640
|
+
if (getters.some((getter) => typeof getter !== "function")) return;
|
|
641
|
+
readers.push({
|
|
642
|
+
constructor,
|
|
643
|
+
from,
|
|
644
|
+
getters
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
const temporal = globalThis.Temporal;
|
|
648
|
+
if (temporal) registerTemporalDurationNamespace(temporal);
|
|
635
649
|
function ToTemporalDurationRecord(input) {
|
|
636
|
-
if (typeof input === "string" &&
|
|
637
|
-
|
|
650
|
+
if (typeof input === "string" && readers.length) {
|
|
651
|
+
const reader = readers[readers.length - 1];
|
|
652
|
+
input = apply(reader.from, reader.constructor, [input]);
|
|
653
|
+
}
|
|
654
|
+
if (input !== null && (typeof input === "object" || typeof input === "function")) for (const reader of readers) {
|
|
638
655
|
let years;
|
|
639
656
|
try {
|
|
640
|
-
years = getters[0]
|
|
657
|
+
years = apply(reader.getters[0], input, []);
|
|
641
658
|
} catch {
|
|
642
|
-
|
|
659
|
+
continue;
|
|
643
660
|
}
|
|
644
661
|
const record = Object.create(null);
|
|
645
662
|
record.years = years;
|
|
646
|
-
for (let
|
|
663
|
+
for (let index = 1; index < fields.length; index++) record[fields[index]] = apply(reader.getters[index], input, []);
|
|
647
664
|
return record;
|
|
648
665
|
}
|
|
649
666
|
return ToDurationRecord(input);
|
|
@@ -1524,6 +1541,9 @@ const TABLE_3 = [
|
|
|
1524
1541
|
* Implements the Intl.DurationFormat API from the TC39 proposal
|
|
1525
1542
|
*/
|
|
1526
1543
|
var DurationFormat = class DurationFormat {
|
|
1544
|
+
static __addTemporalNamespace(namespace) {
|
|
1545
|
+
registerTemporalDurationNamespace(namespace);
|
|
1546
|
+
}
|
|
1527
1547
|
constructor(locales, options) {
|
|
1528
1548
|
if (!(this && this instanceof DurationFormat ? this.constructor : void 0)) throw new TypeError("Intl.DurationFormat must be called with 'new'");
|
|
1529
1549
|
const requestedLocales = CanonicalizeLocaleList(locales);
|