@formatjs/intl-durationformat 0.7.6 → 0.8.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 +1 -1
- package/index.js +1 -4
- package/package.json +15 -9
- package/polyfill-force.js +2 -4
- package/polyfill.js +4 -6
- package/should-polyfill.js +1 -4
- package/src/abstract/DurationRecordSign.d.ts +1 -1
- package/src/abstract/DurationRecordSign.js +3 -6
- package/src/abstract/GetDurationUnitOptions.js +4 -7
- package/src/abstract/IsValidDurationRecord.d.ts +1 -1
- package/src/abstract/IsValidDurationRecord.js +7 -10
- package/src/abstract/PartitionDurationFormatPattern.d.ts +2 -2
- package/src/abstract/PartitionDurationFormatPattern.js +13 -16
- package/src/abstract/ToDurationRecord.d.ts +1 -1
- package/src/abstract/ToDurationRecord.js +14 -17
- package/src/abstract/ToIntegerIfIntegral.js +4 -7
- package/src/constants.d.ts +1 -1
- package/src/constants.js +2 -5
- package/src/core.d.ts +2 -2
- package/src/core.js +33 -38
- package/src/get_internal_slots.d.ts +1 -1
- package/src/get_internal_slots.js +1 -4
- package/src/numbering-systems.generated.js +1 -4
- package/src/time-separators.generated.js +1 -4
- package/src/types.d.ts +2 -2
- package/src/types.js +1 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/polyfill-force.d.ts +0 -1
- package/lib/polyfill-force.js +0 -18
- package/lib/polyfill.d.ts +0 -1
- package/lib/polyfill.js +0 -21
- package/lib/should-polyfill.d.ts +0 -1
- package/lib/should-polyfill.js +0 -3
- package/lib/src/abstract/DurationRecordSign.d.ts +0 -2
- package/lib/src/abstract/DurationRecordSign.js +0 -13
- package/lib/src/abstract/GetDurationUnitOptions.d.ts +0 -4
- package/lib/src/abstract/GetDurationUnitOptions.js +0 -43
- package/lib/src/abstract/IsValidDurationRecord.d.ts +0 -2
- package/lib/src/abstract/IsValidDurationRecord.js +0 -18
- package/lib/src/abstract/PartitionDurationFormatPattern.d.ts +0 -3
- package/lib/src/abstract/PartitionDurationFormatPattern.js +0 -149
- package/lib/src/abstract/ToDurationRecord.d.ts +0 -2
- package/lib/src/abstract/ToDurationRecord.js +0 -68
- package/lib/src/abstract/ToIntegerIfIntegral.d.ts +0 -1
- package/lib/src/abstract/ToIntegerIfIntegral.js +0 -6
- package/lib/src/constants.d.ts +0 -63
- package/lib/src/constants.js +0 -84
- package/lib/src/core.d.ts +0 -14
- package/lib/src/core.js +0 -236
- package/lib/src/get_internal_slots.d.ts +0 -2
- package/lib/src/get_internal_slots.js +0 -9
- package/lib/src/numbering-systems.generated.d.ts +0 -1
- package/lib/src/numbering-systems.generated.js +0 -1
- package/lib/src/time-separators.generated.d.ts +0 -2219
- package/lib/src/time-separators.generated.js +0 -3701
- package/lib/src/types.d.ts +0 -108
- package/lib/src/types.js +0 -2
package/lib/src/core.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { CanonicalizeLocaleList, GetNumberOption, GetOption, OrdinaryHasInstance, SupportedLocales, ToObject, invariant, } from '@formatjs/ecma402-abstract';
|
|
2
|
-
import { ResolveLocale } from '@formatjs/intl-localematcher';
|
|
3
|
-
import { GetDurationUnitOptions } from './abstract/GetDurationUnitOptions';
|
|
4
|
-
import { PartitionDurationFormatPattern } from './abstract/PartitionDurationFormatPattern';
|
|
5
|
-
import { ToDurationRecord } from './abstract/ToDurationRecord';
|
|
6
|
-
import { getInternalSlots } from './get_internal_slots';
|
|
7
|
-
import { numberingSystemNames } from './numbering-systems.generated';
|
|
8
|
-
import { TIME_SEPARATORS } from './time-separators.generated';
|
|
9
|
-
var RESOLVED_OPTIONS_KEYS = [
|
|
10
|
-
'locale',
|
|
11
|
-
'style',
|
|
12
|
-
'years',
|
|
13
|
-
'yearsDisplay',
|
|
14
|
-
'months',
|
|
15
|
-
'monthsDisplay',
|
|
16
|
-
'weeks',
|
|
17
|
-
'weeksDisplay',
|
|
18
|
-
'days',
|
|
19
|
-
'daysDisplay',
|
|
20
|
-
'hours',
|
|
21
|
-
'hoursDisplay',
|
|
22
|
-
'minutes',
|
|
23
|
-
'minutesDisplay',
|
|
24
|
-
'seconds',
|
|
25
|
-
'secondsDisplay',
|
|
26
|
-
'milliseconds',
|
|
27
|
-
'millisecondsDisplay',
|
|
28
|
-
'microseconds',
|
|
29
|
-
'microsecondsDisplay',
|
|
30
|
-
'nanoseconds',
|
|
31
|
-
'nanosecondsDisplay',
|
|
32
|
-
'numberingSystem',
|
|
33
|
-
'fractionalDigits',
|
|
34
|
-
];
|
|
35
|
-
var TABLE_3 = [
|
|
36
|
-
{
|
|
37
|
-
styleSlot: 'years',
|
|
38
|
-
displaySlot: 'yearsDisplay',
|
|
39
|
-
unit: 'years',
|
|
40
|
-
values: ['long', 'short', 'narrow'],
|
|
41
|
-
digitalDefault: 'short',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
styleSlot: 'months',
|
|
45
|
-
displaySlot: 'monthsDisplay',
|
|
46
|
-
unit: 'months',
|
|
47
|
-
values: ['long', 'short', 'narrow'],
|
|
48
|
-
digitalDefault: 'short',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
styleSlot: 'weeks',
|
|
52
|
-
displaySlot: 'weeksDisplay',
|
|
53
|
-
unit: 'weeks',
|
|
54
|
-
values: ['long', 'short', 'narrow'],
|
|
55
|
-
digitalDefault: 'short',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
styleSlot: 'days',
|
|
59
|
-
displaySlot: 'daysDisplay',
|
|
60
|
-
unit: 'days',
|
|
61
|
-
values: ['long', 'short', 'narrow'],
|
|
62
|
-
digitalDefault: 'short',
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
styleSlot: 'hours',
|
|
66
|
-
displaySlot: 'hoursDisplay',
|
|
67
|
-
unit: 'hours',
|
|
68
|
-
values: ['long', 'short', 'narrow', 'numeric', '2-digit'],
|
|
69
|
-
digitalDefault: 'numeric',
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
styleSlot: 'minutes',
|
|
73
|
-
displaySlot: 'minutesDisplay',
|
|
74
|
-
unit: 'minutes',
|
|
75
|
-
values: ['long', 'short', 'narrow', 'numeric', '2-digit'],
|
|
76
|
-
digitalDefault: 'numeric',
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
styleSlot: 'seconds',
|
|
80
|
-
displaySlot: 'secondsDisplay',
|
|
81
|
-
unit: 'seconds',
|
|
82
|
-
values: ['long', 'short', 'narrow', 'numeric', '2-digit'],
|
|
83
|
-
digitalDefault: 'numeric',
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
styleSlot: 'milliseconds',
|
|
87
|
-
displaySlot: 'millisecondsDisplay',
|
|
88
|
-
unit: 'milliseconds',
|
|
89
|
-
values: ['long', 'short', 'narrow', 'numeric'],
|
|
90
|
-
digitalDefault: 'numeric',
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
styleSlot: 'microseconds',
|
|
94
|
-
displaySlot: 'microsecondsDisplay',
|
|
95
|
-
unit: 'microseconds',
|
|
96
|
-
values: ['long', 'short', 'narrow', 'numeric'],
|
|
97
|
-
digitalDefault: 'numeric',
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
styleSlot: 'nanoseconds',
|
|
101
|
-
displaySlot: 'nanosecondsDisplay',
|
|
102
|
-
unit: 'nanoseconds',
|
|
103
|
-
values: ['long', 'short', 'narrow', 'numeric'],
|
|
104
|
-
digitalDefault: 'numeric',
|
|
105
|
-
},
|
|
106
|
-
];
|
|
107
|
-
var DurationFormat = /** @class */ (function () {
|
|
108
|
-
function DurationFormat(locales, options) {
|
|
109
|
-
// test262/test/intl402/ListFormat/constructor/constructor/newtarget-undefined.js
|
|
110
|
-
// Cannot use `new.target` bc of IE11 & TS transpiles it to something else
|
|
111
|
-
var newTarget = this && this instanceof DurationFormat ? this.constructor : void 0;
|
|
112
|
-
if (!newTarget) {
|
|
113
|
-
throw new TypeError("Intl.DurationFormat must be called with 'new'");
|
|
114
|
-
}
|
|
115
|
-
var requestedLocales = CanonicalizeLocaleList(locales);
|
|
116
|
-
var opt = Object.create(null);
|
|
117
|
-
var opts = options === undefined ? Object.create(null) : ToObject(options);
|
|
118
|
-
var matcher = GetOption(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
|
|
119
|
-
var numberingSystem = GetOption(opts, 'numberingSystem', 'string', undefined, undefined);
|
|
120
|
-
if (numberingSystem !== undefined &&
|
|
121
|
-
numberingSystemNames.indexOf(numberingSystem) < 0) {
|
|
122
|
-
// 8.a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal,
|
|
123
|
-
// throw a RangeError exception.
|
|
124
|
-
throw RangeError("Invalid numberingSystems: ".concat(numberingSystem));
|
|
125
|
-
}
|
|
126
|
-
opt.nu = numberingSystem;
|
|
127
|
-
opt.localeMatcher = matcher;
|
|
128
|
-
var localeData = DurationFormat.localeData, availableLocales = DurationFormat.availableLocales;
|
|
129
|
-
var r = ResolveLocale(availableLocales, requestedLocales, opt,
|
|
130
|
-
// [[RelevantExtensionKeys]] slot, which is a constant
|
|
131
|
-
['nu'], localeData, DurationFormat.getDefaultLocale);
|
|
132
|
-
var locale = r.locale;
|
|
133
|
-
var internalSlots = getInternalSlots(this);
|
|
134
|
-
internalSlots.initializedDurationFormat = true;
|
|
135
|
-
internalSlots.locale = locale;
|
|
136
|
-
internalSlots.numberingSystem = r.nu;
|
|
137
|
-
var style = GetOption(opts, 'style', 'string', ['long', 'short', 'narrow', 'digital'], 'short');
|
|
138
|
-
internalSlots.style = style;
|
|
139
|
-
internalSlots.dataLocale = r.dataLocale;
|
|
140
|
-
var prevStyle = '';
|
|
141
|
-
TABLE_3.forEach(function (row) {
|
|
142
|
-
var styleSlot = row.styleSlot, displaySlot = row.displaySlot, unit = row.unit, valueList = row.values, digitalBase = row.digitalDefault;
|
|
143
|
-
var unitOptions = GetDurationUnitOptions(unit, opts, style, valueList, digitalBase, prevStyle);
|
|
144
|
-
internalSlots[styleSlot] = unitOptions.style;
|
|
145
|
-
internalSlots[displaySlot] = unitOptions.display;
|
|
146
|
-
if (unit === 'hours' ||
|
|
147
|
-
unit === 'minutes' ||
|
|
148
|
-
unit === 'seconds' ||
|
|
149
|
-
unit === 'milliseconds' ||
|
|
150
|
-
unit === 'microseconds') {
|
|
151
|
-
prevStyle = unitOptions.style;
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
internalSlots.fractionalDigits = GetNumberOption(opts, 'fractionalDigits', 0, 9, undefined);
|
|
155
|
-
}
|
|
156
|
-
DurationFormat.prototype.resolvedOptions = function () {
|
|
157
|
-
if (typeof this !== 'object' ||
|
|
158
|
-
!OrdinaryHasInstance(DurationFormat, this)) {
|
|
159
|
-
throw TypeError('Method Intl.DurationFormat.prototype.resolvedOptions called on incompatible receiver');
|
|
160
|
-
}
|
|
161
|
-
var internalSlots = getInternalSlots(this);
|
|
162
|
-
var ro = {};
|
|
163
|
-
for (var _i = 0, RESOLVED_OPTIONS_KEYS_1 = RESOLVED_OPTIONS_KEYS; _i < RESOLVED_OPTIONS_KEYS_1.length; _i++) {
|
|
164
|
-
var key = RESOLVED_OPTIONS_KEYS_1[_i];
|
|
165
|
-
var v = internalSlots[key];
|
|
166
|
-
if (key === 'fractionalDigits') {
|
|
167
|
-
if (v !== undefined) {
|
|
168
|
-
v = Number(v);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
invariant(v !== undefined, "Missing internal slot ".concat(key));
|
|
173
|
-
}
|
|
174
|
-
ro[key] = v;
|
|
175
|
-
}
|
|
176
|
-
return ro;
|
|
177
|
-
};
|
|
178
|
-
DurationFormat.prototype.formatToParts = function (duration) {
|
|
179
|
-
var df = this;
|
|
180
|
-
var locInternalSlots = getInternalSlots(this);
|
|
181
|
-
if (locInternalSlots.initializedDurationFormat === undefined) {
|
|
182
|
-
throw new TypeError('Error uninitialized locale');
|
|
183
|
-
}
|
|
184
|
-
var record = ToDurationRecord(duration);
|
|
185
|
-
var parts = PartitionDurationFormatPattern(df, record);
|
|
186
|
-
var result = [];
|
|
187
|
-
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
188
|
-
var _a = parts_1[_i], type = _a.type, unit = _a.unit, value = _a.value;
|
|
189
|
-
var obj = { type: type, value: value };
|
|
190
|
-
if (unit) {
|
|
191
|
-
obj.unit = unit;
|
|
192
|
-
}
|
|
193
|
-
result.push(obj);
|
|
194
|
-
}
|
|
195
|
-
return result;
|
|
196
|
-
};
|
|
197
|
-
DurationFormat.prototype.format = function (duration) {
|
|
198
|
-
var df = this;
|
|
199
|
-
var locInternalSlots = getInternalSlots(this);
|
|
200
|
-
if (locInternalSlots.initializedDurationFormat === undefined) {
|
|
201
|
-
throw new TypeError('Error uninitialized locale');
|
|
202
|
-
}
|
|
203
|
-
var record = ToDurationRecord(duration);
|
|
204
|
-
var parts = PartitionDurationFormatPattern(df, record);
|
|
205
|
-
var result = '';
|
|
206
|
-
for (var _i = 0, parts_2 = parts; _i < parts_2.length; _i++) {
|
|
207
|
-
var value = parts_2[_i].value;
|
|
208
|
-
result += value;
|
|
209
|
-
}
|
|
210
|
-
return result;
|
|
211
|
-
};
|
|
212
|
-
DurationFormat.supportedLocalesOf = function (locales, options) {
|
|
213
|
-
return SupportedLocales(DurationFormat.availableLocales, CanonicalizeLocaleList(locales), options);
|
|
214
|
-
};
|
|
215
|
-
DurationFormat.__defaultLocale = 'en';
|
|
216
|
-
DurationFormat.availableLocales = new Set();
|
|
217
|
-
DurationFormat.localeData = Object.keys(TIME_SEPARATORS.localeData).reduce(function (all, locale) {
|
|
218
|
-
DurationFormat.availableLocales.add(locale);
|
|
219
|
-
var nu = TIME_SEPARATORS.localeData[locale].nu;
|
|
220
|
-
all[locale] = {
|
|
221
|
-
nu: nu,
|
|
222
|
-
digitalFormat: TIME_SEPARATORS.localeData[locale].separator ||
|
|
223
|
-
nu.reduce(function (separators, n) {
|
|
224
|
-
separators[n] = TIME_SEPARATORS.default;
|
|
225
|
-
return separators;
|
|
226
|
-
}, {}),
|
|
227
|
-
};
|
|
228
|
-
return all;
|
|
229
|
-
}, {});
|
|
230
|
-
DurationFormat.getDefaultLocale = function () {
|
|
231
|
-
return DurationFormat.__defaultLocale;
|
|
232
|
-
};
|
|
233
|
-
DurationFormat.polyfilled = true;
|
|
234
|
-
return DurationFormat;
|
|
235
|
-
}());
|
|
236
|
-
export { DurationFormat };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const numberingSystemNames: ReadonlyArray<string>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export var numberingSystemNames = ["adlm", "ahom", "arab", "arabext", "armn", "armnlow", "bali", "beng", "bhks", "brah", "cakm", "cham", "cyrl", "deva", "diak", "ethi", "fullwide", "gara", "geor", "gong", "gonm", "grek", "greklow", "gujr", "gukh", "guru", "hanidays", "hanidec", "hans", "hansfin", "hant", "hantfin", "hebr", "hmng", "hmnp", "java", "jpan", "jpanfin", "jpanyear", "kali", "kawi", "khmr", "knda", "krai", "lana", "lanatham", "laoo", "latn", "lepc", "limb", "mathbold", "mathdbl", "mathmono", "mathsanb", "mathsans", "mlym", "modi", "mong", "mroo", "mtei", "mymr", "mymrepka", "mymrpao", "mymrshan", "mymrtlng", "nagm", "newa", "nkoo", "olck", "onao", "orya", "osma", "outlined", "rohg", "roman", "romanlow", "saur", "segment", "shrd", "sind", "sinh", "sora", "sund", "sunu", "takr", "talu", "taml", "tamldec", "telu", "thai", "tibt", "tirh", "tnsa", "vaii", "wara", "wcho"];
|