@formatjs/intl-relativetimeformat 12.1.1 → 12.1.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/abstract/FormatRelativeTime.d.ts +2 -2
- package/abstract/FormatRelativeTime.js +8 -8
- package/abstract/FormatRelativeTimeToParts.d.ts +2 -2
- package/abstract/FormatRelativeTimeToParts.js +3 -2
- package/abstract/InitializeRelativeTimeFormat.d.ts +7 -7
- package/abstract/InitializeRelativeTimeFormat.js +41 -33
- package/abstract/MakePartsList.js +21 -24
- package/abstract/PartitionRelativeTimePattern.d.ts +3 -3
- package/abstract/PartitionRelativeTimePattern.js +42 -52
- package/abstract/SingularRelativeTimeUnit.d.ts +4 -4
- package/abstract/SingularRelativeTimeUnit.js +17 -32
- package/get_internal_slots.d.ts +3 -1
- package/get_internal_slots.js +8 -7
- package/index.d.ts +13 -13
- package/index.js +103 -119
- package/package.json +6 -6
- package/polyfill-force.js +6 -6
- package/polyfill.iife.js +2302 -3061
- package/polyfill.js +8 -8
- package/should-polyfill.js +16 -24
- package/supported-locales.generated.js +572 -572
package/index.js
CHANGED
|
@@ -1,120 +1,104 @@
|
|
|
1
|
-
import { CanonicalizeLocaleList, SupportedLocales, ToString
|
|
2
|
-
import { InitializeRelativeTimeFormat } from
|
|
3
|
-
import { PartitionRelativeTimePattern } from
|
|
4
|
-
import getInternalSlots from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
RelativeTimeFormat.getDefaultLocale = function () {
|
|
83
|
-
return RelativeTimeFormat.__defaultLocale;
|
|
84
|
-
};
|
|
85
|
-
RelativeTimeFormat.localeData = {};
|
|
86
|
-
RelativeTimeFormat.availableLocales = new Set();
|
|
87
|
-
RelativeTimeFormat.__defaultLocale = '';
|
|
88
|
-
RelativeTimeFormat.relevantExtensionKeys = ['nu'];
|
|
89
|
-
RelativeTimeFormat.polyfilled = true;
|
|
90
|
-
return RelativeTimeFormat;
|
|
91
|
-
}());
|
|
92
|
-
export default RelativeTimeFormat;
|
|
93
|
-
try {
|
|
94
|
-
// IE11 does not have Symbol
|
|
95
|
-
if (typeof Symbol !== 'undefined') {
|
|
96
|
-
Object.defineProperty(RelativeTimeFormat.prototype, Symbol.toStringTag, {
|
|
97
|
-
value: 'Intl.RelativeTimeFormat',
|
|
98
|
-
writable: false,
|
|
99
|
-
enumerable: false,
|
|
100
|
-
configurable: true,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
// https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/length.js
|
|
104
|
-
Object.defineProperty(RelativeTimeFormat.prototype.constructor, 'length', {
|
|
105
|
-
value: 0,
|
|
106
|
-
writable: false,
|
|
107
|
-
enumerable: false,
|
|
108
|
-
configurable: true,
|
|
109
|
-
});
|
|
110
|
-
// https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/length.js
|
|
111
|
-
Object.defineProperty(RelativeTimeFormat.supportedLocalesOf, 'length', {
|
|
112
|
-
value: 1,
|
|
113
|
-
writable: false,
|
|
114
|
-
enumerable: false,
|
|
115
|
-
configurable: true,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
catch (_a) {
|
|
119
|
-
// Meta fix so we're test262-compliant, not important
|
|
1
|
+
import { CanonicalizeLocaleList, SupportedLocales, ToString } from "@formatjs/ecma402-abstract";
|
|
2
|
+
import { InitializeRelativeTimeFormat } from "./abstract/InitializeRelativeTimeFormat.js";
|
|
3
|
+
import { PartitionRelativeTimePattern } from "./abstract/PartitionRelativeTimePattern.js";
|
|
4
|
+
import getInternalSlots from "./get_internal_slots.js";
|
|
5
|
+
export default class RelativeTimeFormat {
|
|
6
|
+
constructor(locales, options) {
|
|
7
|
+
// test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
|
|
8
|
+
// Cannot use `new.target` bc of IE11 & TS transpiles it to something else
|
|
9
|
+
const newTarget = this && this instanceof RelativeTimeFormat ? this.constructor : void 0;
|
|
10
|
+
if (!newTarget) {
|
|
11
|
+
throw new TypeError("Intl.RelativeTimeFormat must be called with 'new'");
|
|
12
|
+
}
|
|
13
|
+
return InitializeRelativeTimeFormat(this, locales, options, {
|
|
14
|
+
getInternalSlots,
|
|
15
|
+
availableLocales: RelativeTimeFormat.availableLocales,
|
|
16
|
+
relevantExtensionKeys: RelativeTimeFormat.relevantExtensionKeys,
|
|
17
|
+
localeData: RelativeTimeFormat.localeData,
|
|
18
|
+
getDefaultLocale: RelativeTimeFormat.getDefaultLocale
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
format(value, unit) {
|
|
22
|
+
if (typeof this !== "object") {
|
|
23
|
+
throw new TypeError("format was called on a non-object");
|
|
24
|
+
}
|
|
25
|
+
const internalSlots = getInternalSlots(this);
|
|
26
|
+
if (!internalSlots.initializedRelativeTimeFormat) {
|
|
27
|
+
throw new TypeError("format was called on a invalid context");
|
|
28
|
+
}
|
|
29
|
+
return PartitionRelativeTimePattern(this, Number(value), ToString(unit), { getInternalSlots }).map((el) => el.value).join("");
|
|
30
|
+
}
|
|
31
|
+
formatToParts(value, unit) {
|
|
32
|
+
if (typeof this !== "object") {
|
|
33
|
+
throw new TypeError("formatToParts was called on a non-object");
|
|
34
|
+
}
|
|
35
|
+
const internalSlots = getInternalSlots(this);
|
|
36
|
+
if (!internalSlots.initializedRelativeTimeFormat) {
|
|
37
|
+
throw new TypeError("formatToParts was called on a invalid context");
|
|
38
|
+
}
|
|
39
|
+
return PartitionRelativeTimePattern(this, Number(value), ToString(unit), { getInternalSlots });
|
|
40
|
+
}
|
|
41
|
+
resolvedOptions() {
|
|
42
|
+
if (typeof this !== "object") {
|
|
43
|
+
throw new TypeError("resolvedOptions was called on a non-object");
|
|
44
|
+
}
|
|
45
|
+
const internalSlots = getInternalSlots(this);
|
|
46
|
+
if (!internalSlots.initializedRelativeTimeFormat) {
|
|
47
|
+
throw new TypeError("resolvedOptions was called on a invalid context");
|
|
48
|
+
}
|
|
49
|
+
// test262/test/intl402/RelativeTimeFormat/prototype/resolvedOptions/type.js
|
|
50
|
+
return {
|
|
51
|
+
locale: internalSlots.locale,
|
|
52
|
+
style: internalSlots.style,
|
|
53
|
+
numeric: internalSlots.numeric,
|
|
54
|
+
numberingSystem: internalSlots.numberingSystem
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
static supportedLocalesOf(locales, options) {
|
|
58
|
+
return SupportedLocales(RelativeTimeFormat.availableLocales, CanonicalizeLocaleList(locales), options);
|
|
59
|
+
}
|
|
60
|
+
static __addLocaleData(...data) {
|
|
61
|
+
for (const { data: d, locale } of data) {
|
|
62
|
+
const minimizedLocale = new Intl.Locale(locale).minimize().toString();
|
|
63
|
+
RelativeTimeFormat.localeData[locale] = RelativeTimeFormat.localeData[minimizedLocale] = d;
|
|
64
|
+
RelativeTimeFormat.availableLocales.add(minimizedLocale);
|
|
65
|
+
RelativeTimeFormat.availableLocales.add(locale);
|
|
66
|
+
if (!RelativeTimeFormat.__defaultLocale) {
|
|
67
|
+
RelativeTimeFormat.__defaultLocale = minimizedLocale;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
static localeData = {};
|
|
72
|
+
static availableLocales = new Set();
|
|
73
|
+
static __defaultLocale = "";
|
|
74
|
+
static getDefaultLocale() {
|
|
75
|
+
return RelativeTimeFormat.__defaultLocale;
|
|
76
|
+
}
|
|
77
|
+
static relevantExtensionKeys = ["nu"];
|
|
78
|
+
static polyfilled = true;
|
|
120
79
|
}
|
|
80
|
+
try {
|
|
81
|
+
// IE11 does not have Symbol
|
|
82
|
+
if (typeof Symbol !== "undefined") {
|
|
83
|
+
Object.defineProperty(RelativeTimeFormat.prototype, Symbol.toStringTag, {
|
|
84
|
+
value: "Intl.RelativeTimeFormat",
|
|
85
|
+
writable: false,
|
|
86
|
+
enumerable: false,
|
|
87
|
+
configurable: true
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/length.js
|
|
91
|
+
Object.defineProperty(RelativeTimeFormat.prototype.constructor, "length", {
|
|
92
|
+
value: 0,
|
|
93
|
+
writable: false,
|
|
94
|
+
enumerable: false,
|
|
95
|
+
configurable: true
|
|
96
|
+
});
|
|
97
|
+
// https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/length.js
|
|
98
|
+
Object.defineProperty(RelativeTimeFormat.supportedLocalesOf, "length", {
|
|
99
|
+
value: 1,
|
|
100
|
+
writable: false,
|
|
101
|
+
enumerable: false,
|
|
102
|
+
configurable: true
|
|
103
|
+
});
|
|
104
|
+
} catch {}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-relativetimeformat",
|
|
3
3
|
"description": "Formats JavaScript dates to relative time strings.",
|
|
4
|
-
"version": "12.1.
|
|
4
|
+
"version": "12.1.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Long Ho <holevietlong@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"tslib": "^2.8.0",
|
|
18
|
-
"@formatjs/
|
|
19
|
-
"@formatjs/
|
|
18
|
+
"@formatjs/intl-localematcher": "0.7.5",
|
|
19
|
+
"@formatjs/ecma402-abstract": "3.0.8"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@formatjs/intl-
|
|
23
|
-
"@formatjs/intl-pluralrules": "6.1.
|
|
24
|
-
"@formatjs/intl-
|
|
22
|
+
"@formatjs/intl-getcanonicallocales": "3.1.2",
|
|
23
|
+
"@formatjs/intl-pluralrules": "6.1.2",
|
|
24
|
+
"@formatjs/intl-locale": "5.1.2"
|
|
25
25
|
},
|
|
26
26
|
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
27
27
|
"gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c",
|
package/polyfill-force.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import RelativeTimeFormat from
|
|
2
|
-
Object.defineProperty(Intl,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import RelativeTimeFormat from "./index.js";
|
|
2
|
+
Object.defineProperty(Intl, "RelativeTimeFormat", {
|
|
3
|
+
value: RelativeTimeFormat,
|
|
4
|
+
writable: true,
|
|
5
|
+
enumerable: false,
|
|
6
|
+
configurable: true
|
|
7
7
|
});
|