@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/index.js CHANGED
@@ -1,120 +1,104 @@
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
- var RelativeTimeFormat = /** @class */ (function () {
6
- function RelativeTimeFormat(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
- var 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: getInternalSlots,
15
- availableLocales: RelativeTimeFormat.availableLocales,
16
- relevantExtensionKeys: RelativeTimeFormat.relevantExtensionKeys,
17
- localeData: RelativeTimeFormat.localeData,
18
- getDefaultLocale: RelativeTimeFormat.getDefaultLocale,
19
- });
20
- }
21
- RelativeTimeFormat.prototype.format = function (value, unit) {
22
- if (typeof this !== 'object') {
23
- throw new TypeError('format was called on a non-object');
24
- }
25
- var 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), {
30
- getInternalSlots: getInternalSlots,
31
- })
32
- .map(function (el) { return el.value; })
33
- .join('');
34
- };
35
- RelativeTimeFormat.prototype.formatToParts = function (value, unit) {
36
- if (typeof this !== 'object') {
37
- throw new TypeError('formatToParts was called on a non-object');
38
- }
39
- var internalSlots = getInternalSlots(this);
40
- if (!internalSlots.initializedRelativeTimeFormat) {
41
- throw new TypeError('formatToParts was called on a invalid context');
42
- }
43
- return PartitionRelativeTimePattern(this, Number(value), ToString(unit), { getInternalSlots: getInternalSlots });
44
- };
45
- RelativeTimeFormat.prototype.resolvedOptions = function () {
46
- if (typeof this !== 'object') {
47
- throw new TypeError('resolvedOptions was called on a non-object');
48
- }
49
- var internalSlots = getInternalSlots(this);
50
- if (!internalSlots.initializedRelativeTimeFormat) {
51
- throw new TypeError('resolvedOptions was called on a invalid context');
52
- }
53
- // test262/test/intl402/RelativeTimeFormat/prototype/resolvedOptions/type.js
54
- return {
55
- locale: internalSlots.locale,
56
- style: internalSlots.style,
57
- numeric: internalSlots.numeric,
58
- numberingSystem: internalSlots.numberingSystem,
59
- };
60
- };
61
- RelativeTimeFormat.supportedLocalesOf = function (locales, options) {
62
- return SupportedLocales(RelativeTimeFormat.availableLocales, CanonicalizeLocaleList(locales), options);
63
- };
64
- RelativeTimeFormat.__addLocaleData = function () {
65
- var data = [];
66
- for (var _i = 0; _i < arguments.length; _i++) {
67
- data[_i] = arguments[_i];
68
- }
69
- for (var _a = 0, data_1 = data; _a < data_1.length; _a++) {
70
- var _b = data_1[_a], d = _b.data, locale = _b.locale;
71
- var minimizedLocale = new Intl.Locale(locale)
72
- .minimize()
73
- .toString();
74
- RelativeTimeFormat.localeData[locale] = RelativeTimeFormat.localeData[minimizedLocale] = d;
75
- RelativeTimeFormat.availableLocales.add(minimizedLocale);
76
- RelativeTimeFormat.availableLocales.add(locale);
77
- if (!RelativeTimeFormat.__defaultLocale) {
78
- RelativeTimeFormat.__defaultLocale = minimizedLocale;
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.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/ecma402-abstract": "3.0.7",
19
- "@formatjs/intl-localematcher": "0.7.4"
18
+ "@formatjs/intl-localematcher": "0.7.5",
19
+ "@formatjs/ecma402-abstract": "3.0.8"
20
20
  },
21
21
  "devDependencies": {
22
- "@formatjs/intl-locale": "5.1.1",
23
- "@formatjs/intl-pluralrules": "6.1.1",
24
- "@formatjs/intl-getcanonicallocales": "3.1.1"
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 './index.js';
2
- Object.defineProperty(Intl, 'RelativeTimeFormat', {
3
- value: RelativeTimeFormat,
4
- writable: true,
5
- enumerable: false,
6
- configurable: true,
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
  });