@formatjs/intl-durationformat 0.10.3 → 0.10.4

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.
Files changed (37) hide show
  1. package/index.d.ts +78 -1
  2. package/index.js +2179 -1
  3. package/index.js.map +1 -0
  4. package/package.json +2 -3
  5. package/polyfill-force.d.ts +1 -1
  6. package/polyfill-force.js +2182 -7
  7. package/polyfill-force.js.map +1 -0
  8. package/polyfill.d.ts +1 -1
  9. package/polyfill.js +2187 -10
  10. package/polyfill.js.map +1 -0
  11. package/should-polyfill.d.ts +5 -1
  12. package/should-polyfill.js +6 -1
  13. package/should-polyfill.js.map +1 -0
  14. package/src/abstract/DurationRecordSign.d.ts +0 -2
  15. package/src/abstract/DurationRecordSign.js +0 -13
  16. package/src/abstract/GetDurationUnitOptions.d.ts +0 -4
  17. package/src/abstract/GetDurationUnitOptions.js +0 -36
  18. package/src/abstract/IsValidDurationRecord.d.ts +0 -2
  19. package/src/abstract/IsValidDurationRecord.js +0 -18
  20. package/src/abstract/PartitionDurationFormatPattern.d.ts +0 -3
  21. package/src/abstract/PartitionDurationFormatPattern.js +0 -129
  22. package/src/abstract/ToDurationRecord.d.ts +0 -2
  23. package/src/abstract/ToDurationRecord.js +0 -60
  24. package/src/abstract/ToIntegerIfIntegral.d.ts +0 -1
  25. package/src/abstract/ToIntegerIfIntegral.js +0 -6
  26. package/src/constants.d.ts +0 -63
  27. package/src/constants.js +0 -85
  28. package/src/core.d.ts +0 -18
  29. package/src/core.js +0 -308
  30. package/src/get_internal_slots.d.ts +0 -2
  31. package/src/get_internal_slots.js +0 -9
  32. package/src/numbering-systems.generated.d.ts +0 -1
  33. package/src/numbering-systems.generated.js +0 -99
  34. package/src/time-separators.generated.d.ts +0 -2342
  35. package/src/time-separators.generated.js +0 -812
  36. package/src/types.d.ts +0 -108
  37. package/src/types.js +0 -1
@@ -1,129 +0,0 @@
1
- import { createMemoizedListFormat, createMemoizedNumberFormat, invariant } from "@formatjs/ecma402-abstract";
2
- import { TABLE_2 } from "../constants.js";
3
- import { DurationFormat } from "../core.js";
4
- import { getInternalSlots } from "../get_internal_slots.js";
5
- import "../types.js";
6
- export function PartitionDurationFormatPattern(df, duration) {
7
- const result = [];
8
- let done = false;
9
- let separated = false;
10
- const internalSlots = getInternalSlots(df);
11
- let dataLocale = internalSlots.dataLocale;
12
- const dataLocaleData = DurationFormat.localeData[dataLocale];
13
- if (!dataLocaleData) {
14
- throw new TypeError("Invalid locale");
15
- }
16
- const numberingSystem = internalSlots.numberingSystem;
17
- const separator = dataLocaleData.digitalFormat[numberingSystem];
18
- for (let i = 0; i < TABLE_2.length && !done; i++) {
19
- const row = TABLE_2[i];
20
- let value = duration[row.valueField];
21
- const style = internalSlots[row.styleSlot];
22
- const display = internalSlots[row.displaySlot];
23
- const { unit, numberFormatUnit } = row;
24
- const nfOpts = Object.create(null);
25
- if (unit === "seconds" || unit === "milliseconds" || unit === "microseconds") {
26
- let nextStyle;
27
- if (unit === "seconds") {
28
- nextStyle = internalSlots.milliseconds;
29
- } else if (unit === "milliseconds") {
30
- nextStyle = internalSlots.microseconds;
31
- } else {
32
- nextStyle = internalSlots.nanoseconds;
33
- }
34
- if (nextStyle === "numeric") {
35
- if (unit === "seconds") {
36
- value += duration.milliseconds / 1e3 + duration.microseconds / 1e6 + duration.nanoseconds / 1e9;
37
- } else if (unit === "milliseconds") {
38
- value += duration.microseconds / 1e3 + duration.nanoseconds / 1e6;
39
- } else {
40
- value += duration.nanoseconds / 1e3;
41
- }
42
- if (internalSlots.fractionalDigits === undefined) {
43
- nfOpts.maximumFractionDigits = 9;
44
- nfOpts.minimumFractionDigits = 0;
45
- } else {
46
- nfOpts.maximumFractionDigits = internalSlots.fractionalDigits;
47
- nfOpts.minimumFractionDigits = internalSlots.fractionalDigits;
48
- }
49
- nfOpts.roundingMode = "trunc";
50
- done = true;
51
- }
52
- }
53
- if (value !== 0 || display !== "auto") {
54
- nfOpts.numberingSystem = internalSlots.numberingSystem;
55
- if (style === "2-digit") {
56
- nfOpts.minimumIntegerDigits = 2;
57
- }
58
- if (style !== "2-digit" && style !== "numeric") {
59
- nfOpts.style = "unit";
60
- nfOpts.unit = numberFormatUnit;
61
- nfOpts.unitDisplay = style;
62
- }
63
- const nf = createMemoizedNumberFormat(internalSlots.locale, nfOpts);
64
- let list;
65
- if (!separated) {
66
- list = [];
67
- } else {
68
- list = result[result.length - 1];
69
- list.push({
70
- type: "literal",
71
- value: separator
72
- });
73
- }
74
- let parts = nf.formatToParts(value);
75
- parts.forEach(({ type, value }) => {
76
- list.push({
77
- type,
78
- value,
79
- unit: numberFormatUnit
80
- });
81
- });
82
- if (!separated) {
83
- if (style === "2-digit" || style === "numeric") {
84
- separated = true;
85
- }
86
- result.push(list);
87
- }
88
- } else {
89
- separated = false;
90
- }
91
- }
92
- const lfOpts = Object.create(null);
93
- lfOpts.type = "unit";
94
- let listStyle = internalSlots.style;
95
- if (listStyle === "digital") {
96
- listStyle = "short";
97
- }
98
- lfOpts.style = listStyle;
99
- const lf = createMemoizedListFormat(internalSlots.locale, lfOpts);
100
- const strings = [];
101
- for (const parts of result) {
102
- let string = "";
103
- for (const { value } of parts) {
104
- string += value;
105
- }
106
- strings.push(string);
107
- }
108
- let formatted = lf.formatToParts(strings);
109
- let resultIndex = 0;
110
- let resultLength = result.length;
111
- let flattened = [];
112
- for (const { type, value } of formatted) {
113
- if (type === "element") {
114
- invariant(resultIndex < resultLength, "Index out of bounds");
115
- let parts = result[resultIndex];
116
- for (const part of parts) {
117
- flattened.push(part);
118
- }
119
- resultIndex++;
120
- } else {
121
- invariant(type === "literal", "Type must be literal");
122
- flattened.push({
123
- type: "literal",
124
- value
125
- });
126
- }
127
- }
128
- return flattened;
129
- }
@@ -1,2 +0,0 @@
1
- import { type DurationInput, type DurationRecord } from "../types.js";
2
- export declare function ToDurationRecord(input: DurationInput): DurationRecord;
@@ -1,60 +0,0 @@
1
- import "../types.js";
2
- import { IsValidDurationRecord } from "./IsValidDurationRecord.js";
3
- import { ToIntegerIfIntegral } from "./ToIntegerIfIntegral.js";
4
- export function ToDurationRecord(input) {
5
- if (typeof input !== "object") {
6
- if (typeof input === "string") {
7
- throw new RangeError("Invalid duration format");
8
- }
9
- throw new TypeError("Invalid duration");
10
- }
11
- const result = {
12
- years: 0,
13
- months: 0,
14
- weeks: 0,
15
- days: 0,
16
- hours: 0,
17
- minutes: 0,
18
- seconds: 0,
19
- milliseconds: 0,
20
- microseconds: 0,
21
- nanoseconds: 0
22
- };
23
- if (input.days !== undefined) {
24
- result.days = ToIntegerIfIntegral(input.days);
25
- }
26
- if (input.hours !== undefined) {
27
- result.hours = ToIntegerIfIntegral(input.hours);
28
- }
29
- if (input.microseconds !== undefined) {
30
- result.microseconds = ToIntegerIfIntegral(input.microseconds);
31
- }
32
- if (input.milliseconds !== undefined) {
33
- result.milliseconds = ToIntegerIfIntegral(input.milliseconds);
34
- }
35
- if (input.minutes !== undefined) {
36
- result.minutes = ToIntegerIfIntegral(input.minutes);
37
- }
38
- if (input.months !== undefined) {
39
- result.months = ToIntegerIfIntegral(input.months);
40
- }
41
- if (input.nanoseconds !== undefined) {
42
- result.nanoseconds = ToIntegerIfIntegral(input.nanoseconds);
43
- }
44
- if (input.seconds !== undefined) {
45
- result.seconds = ToIntegerIfIntegral(input.seconds);
46
- }
47
- if (input.weeks !== undefined) {
48
- result.weeks = ToIntegerIfIntegral(input.weeks);
49
- }
50
- if (input.years !== undefined) {
51
- result.years = ToIntegerIfIntegral(input.years);
52
- }
53
- if (input.years === undefined && input.months === undefined && input.weeks === undefined && input.days === undefined && input.hours === undefined && input.minutes === undefined && input.seconds === undefined && input.milliseconds === undefined && input.microseconds === undefined && input.nanoseconds === undefined) {
54
- throw new TypeError("Invalid duration format");
55
- }
56
- if (!IsValidDurationRecord(result)) {
57
- throw new RangeError("Invalid duration format");
58
- }
59
- return result;
60
- }
@@ -1 +0,0 @@
1
- export declare function ToIntegerIfIntegral(arg: any): number;
@@ -1,6 +0,0 @@
1
- import { invariant, ToNumber } from "@formatjs/ecma402-abstract";
2
- export function ToIntegerIfIntegral(arg) {
3
- const number = ToNumber(arg);
4
- invariant(number.isInteger(), `${arg} is not an integer`);
5
- return number.toNumber();
6
- }
@@ -1,63 +0,0 @@
1
- import { type DurationRecord } from "./types.js";
2
- export declare const TABLE_1: Array<keyof DurationRecord>;
3
- export declare const TABLE_2: readonly [{
4
- readonly valueField: "years";
5
- readonly styleSlot: "years";
6
- readonly displaySlot: "yearsDisplay";
7
- readonly unit: "years";
8
- readonly numberFormatUnit: "year";
9
- }, {
10
- readonly valueField: "months";
11
- readonly styleSlot: "months";
12
- readonly displaySlot: "monthsDisplay";
13
- readonly unit: "months";
14
- readonly numberFormatUnit: "month";
15
- }, {
16
- readonly valueField: "weeks";
17
- readonly styleSlot: "weeks";
18
- readonly displaySlot: "weeksDisplay";
19
- readonly unit: "weeks";
20
- readonly numberFormatUnit: "week";
21
- }, {
22
- readonly valueField: "days";
23
- readonly styleSlot: "days";
24
- readonly displaySlot: "daysDisplay";
25
- readonly unit: "days";
26
- readonly numberFormatUnit: "day";
27
- }, {
28
- readonly valueField: "hours";
29
- readonly styleSlot: "hours";
30
- readonly displaySlot: "hoursDisplay";
31
- readonly unit: "hours";
32
- readonly numberFormatUnit: "hour";
33
- }, {
34
- readonly valueField: "minutes";
35
- readonly styleSlot: "minutes";
36
- readonly displaySlot: "minutesDisplay";
37
- readonly unit: "minutes";
38
- readonly numberFormatUnit: "minute";
39
- }, {
40
- readonly valueField: "seconds";
41
- readonly styleSlot: "seconds";
42
- readonly displaySlot: "secondsDisplay";
43
- readonly unit: "seconds";
44
- readonly numberFormatUnit: "second";
45
- }, {
46
- readonly valueField: "milliseconds";
47
- readonly styleSlot: "milliseconds";
48
- readonly displaySlot: "millisecondsDisplay";
49
- readonly unit: "milliseconds";
50
- readonly numberFormatUnit: "millisecond";
51
- }, {
52
- readonly valueField: "microseconds";
53
- readonly styleSlot: "microseconds";
54
- readonly displaySlot: "microsecondsDisplay";
55
- readonly unit: "microseconds";
56
- readonly numberFormatUnit: "microsecond";
57
- }, {
58
- readonly valueField: "nanoseconds";
59
- readonly styleSlot: "nanoseconds";
60
- readonly displaySlot: "nanosecondsDisplay";
61
- readonly unit: "nanoseconds";
62
- readonly numberFormatUnit: "nanosecond";
63
- }];
package/src/constants.js DELETED
@@ -1,85 +0,0 @@
1
- import "./types.js";
2
- export const TABLE_1 = [
3
- "years",
4
- "months",
5
- "weeks",
6
- "days",
7
- "hours",
8
- "minutes",
9
- "seconds",
10
- "milliseconds",
11
- "microseconds",
12
- "nanoseconds"
13
- ];
14
- export const TABLE_2 = [
15
- {
16
- valueField: "years",
17
- styleSlot: "years",
18
- displaySlot: "yearsDisplay",
19
- unit: "years",
20
- numberFormatUnit: "year"
21
- },
22
- {
23
- valueField: "months",
24
- styleSlot: "months",
25
- displaySlot: "monthsDisplay",
26
- unit: "months",
27
- numberFormatUnit: "month"
28
- },
29
- {
30
- valueField: "weeks",
31
- styleSlot: "weeks",
32
- displaySlot: "weeksDisplay",
33
- unit: "weeks",
34
- numberFormatUnit: "week"
35
- },
36
- {
37
- valueField: "days",
38
- styleSlot: "days",
39
- displaySlot: "daysDisplay",
40
- unit: "days",
41
- numberFormatUnit: "day"
42
- },
43
- {
44
- valueField: "hours",
45
- styleSlot: "hours",
46
- displaySlot: "hoursDisplay",
47
- unit: "hours",
48
- numberFormatUnit: "hour"
49
- },
50
- {
51
- valueField: "minutes",
52
- styleSlot: "minutes",
53
- displaySlot: "minutesDisplay",
54
- unit: "minutes",
55
- numberFormatUnit: "minute"
56
- },
57
- {
58
- valueField: "seconds",
59
- styleSlot: "seconds",
60
- displaySlot: "secondsDisplay",
61
- unit: "seconds",
62
- numberFormatUnit: "second"
63
- },
64
- {
65
- valueField: "milliseconds",
66
- styleSlot: "milliseconds",
67
- displaySlot: "millisecondsDisplay",
68
- unit: "milliseconds",
69
- numberFormatUnit: "millisecond"
70
- },
71
- {
72
- valueField: "microseconds",
73
- styleSlot: "microseconds",
74
- displaySlot: "microsecondsDisplay",
75
- unit: "microseconds",
76
- numberFormatUnit: "microsecond"
77
- },
78
- {
79
- valueField: "nanoseconds",
80
- styleSlot: "nanoseconds",
81
- displaySlot: "nanosecondsDisplay",
82
- unit: "nanoseconds",
83
- numberFormatUnit: "nanosecond"
84
- }
85
- ];
package/src/core.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import type { DurationFormatLocaleInternalData, DurationFormatPart, DurationFormat as DurationFormatType, DurationInput, ResolvedDurationFormatOptions } from "./types.js";
2
- import { type DurationFormatOptions } from "./types.js";
3
- /**
4
- * DurationFormat provides locale-sensitive duration formatting
5
- * Implements the Intl.DurationFormat API from the TC39 proposal
6
- */
7
- export declare class DurationFormat implements DurationFormatType {
8
- constructor(locales?: string | string[], options?: DurationFormatOptions);
9
- resolvedOptions(): ResolvedDurationFormatOptions;
10
- formatToParts(duration: DurationInput): DurationFormatPart[];
11
- format(duration: DurationInput): string;
12
- static supportedLocalesOf(locales: string | string[], options?: Pick<DurationFormatOptions, "localeMatcher">): string[];
13
- static __defaultLocale: string;
14
- static availableLocales: Set<string>;
15
- static localeData: Record<string, DurationFormatLocaleInternalData | undefined>;
16
- static getDefaultLocale: () => string;
17
- static polyfilled: boolean;
18
- }
package/src/core.js DELETED
@@ -1,308 +0,0 @@
1
- // Core implementation of Intl.DurationFormat polyfill
2
- // Follows the TC39 Intl.DurationFormat proposal specification
3
- import { CanonicalizeLocaleList, GetNumberOption, GetOption, OrdinaryHasInstance, SupportedLocales, ToObject, invariant } from "@formatjs/ecma402-abstract";
4
- import { ResolveLocale } from "@formatjs/intl-localematcher";
5
- import { GetDurationUnitOptions } from "./abstract/GetDurationUnitOptions.js";
6
- import { PartitionDurationFormatPattern } from "./abstract/PartitionDurationFormatPattern.js";
7
- import { ToDurationRecord } from "./abstract/ToDurationRecord.js";
8
- import { getInternalSlots } from "./get_internal_slots.js";
9
- import { numberingSystemNames } from "./numbering-systems.generated.js";
10
- import { TIME_SEPARATORS } from "./time-separators.generated.js";
11
- import "./types.js";
12
- // Keys that should be included in resolvedOptions() output
13
- // These represent all the configurable options for duration formatting
14
- const RESOLVED_OPTIONS_KEYS = [
15
- "locale",
16
- "style",
17
- "years",
18
- "yearsDisplay",
19
- "months",
20
- "monthsDisplay",
21
- "weeks",
22
- "weeksDisplay",
23
- "days",
24
- "daysDisplay",
25
- "hours",
26
- "hoursDisplay",
27
- "minutes",
28
- "minutesDisplay",
29
- "seconds",
30
- "secondsDisplay",
31
- "milliseconds",
32
- "millisecondsDisplay",
33
- "microseconds",
34
- "microsecondsDisplay",
35
- "nanoseconds",
36
- "nanosecondsDisplay",
37
- "numberingSystem",
38
- "fractionalDigits"
39
- ];
40
- // Configuration table for all duration units (from spec Table 3)
41
- // Defines the style and display options for each unit, along with their defaults
42
- // Units are processed in order from largest (years) to smallest (nanoseconds)
43
- const TABLE_3 = [
44
- {
45
- styleSlot: "years",
46
- displaySlot: "yearsDisplay",
47
- unit: "years",
48
- values: [
49
- "long",
50
- "short",
51
- "narrow"
52
- ],
53
- digitalDefault: "short"
54
- },
55
- {
56
- styleSlot: "months",
57
- displaySlot: "monthsDisplay",
58
- unit: "months",
59
- values: [
60
- "long",
61
- "short",
62
- "narrow"
63
- ],
64
- digitalDefault: "short"
65
- },
66
- {
67
- styleSlot: "weeks",
68
- displaySlot: "weeksDisplay",
69
- unit: "weeks",
70
- values: [
71
- "long",
72
- "short",
73
- "narrow"
74
- ],
75
- digitalDefault: "short"
76
- },
77
- {
78
- styleSlot: "days",
79
- displaySlot: "daysDisplay",
80
- unit: "days",
81
- values: [
82
- "long",
83
- "short",
84
- "narrow"
85
- ],
86
- digitalDefault: "short"
87
- },
88
- {
89
- styleSlot: "hours",
90
- displaySlot: "hoursDisplay",
91
- unit: "hours",
92
- values: [
93
- "long",
94
- "short",
95
- "narrow",
96
- "numeric",
97
- "2-digit"
98
- ],
99
- digitalDefault: "numeric"
100
- },
101
- {
102
- styleSlot: "minutes",
103
- displaySlot: "minutesDisplay",
104
- unit: "minutes",
105
- values: [
106
- "long",
107
- "short",
108
- "narrow",
109
- "numeric",
110
- "2-digit"
111
- ],
112
- digitalDefault: "numeric"
113
- },
114
- {
115
- styleSlot: "seconds",
116
- displaySlot: "secondsDisplay",
117
- unit: "seconds",
118
- values: [
119
- "long",
120
- "short",
121
- "narrow",
122
- "numeric",
123
- "2-digit"
124
- ],
125
- digitalDefault: "numeric"
126
- },
127
- {
128
- styleSlot: "milliseconds",
129
- displaySlot: "millisecondsDisplay",
130
- unit: "milliseconds",
131
- values: [
132
- "long",
133
- "short",
134
- "narrow",
135
- "numeric"
136
- ],
137
- digitalDefault: "numeric"
138
- },
139
- {
140
- styleSlot: "microseconds",
141
- displaySlot: "microsecondsDisplay",
142
- unit: "microseconds",
143
- values: [
144
- "long",
145
- "short",
146
- "narrow",
147
- "numeric"
148
- ],
149
- digitalDefault: "numeric"
150
- },
151
- {
152
- styleSlot: "nanoseconds",
153
- displaySlot: "nanosecondsDisplay",
154
- unit: "nanoseconds",
155
- values: [
156
- "long",
157
- "short",
158
- "narrow",
159
- "numeric"
160
- ],
161
- digitalDefault: "numeric"
162
- }
163
- ];
164
- /**
165
- * DurationFormat provides locale-sensitive duration formatting
166
- * Implements the Intl.DurationFormat API from the TC39 proposal
167
- */
168
- export class DurationFormat {
169
- constructor(locales, options) {
170
- // Ensure constructor is called with 'new' keyword
171
- // test262/test/intl402/ListFormat/constructor/constructor/newtarget-undefined.js
172
- // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
173
- const newTarget = this && this instanceof DurationFormat ? this.constructor : void 0;
174
- if (!newTarget) {
175
- throw new TypeError("Intl.DurationFormat must be called with 'new'");
176
- }
177
- // Canonicalize the requested locales into a standard format
178
- const requestedLocales = CanonicalizeLocaleList(locales);
179
- const opt = Object.create(null);
180
- const opts = options === undefined ? Object.create(null) : ToObject(options);
181
- // Get locale matching algorithm preference ('best fit' or 'lookup')
182
- const matcher = GetOption(opts, "localeMatcher", "string", ["best fit", "lookup"], "best fit");
183
- // Get numbering system (e.g., 'latn', 'arab', 'deva')
184
- const numberingSystem = GetOption(opts, "numberingSystem", "string", undefined, undefined);
185
- if (numberingSystem !== undefined && numberingSystemNames.indexOf(numberingSystem) < 0) {
186
- // Validate that the numbering system is recognized
187
- throw RangeError(`Invalid numberingSystems: ${numberingSystem}`);
188
- }
189
- opt.nu = numberingSystem;
190
- opt.localeMatcher = matcher;
191
- // Resolve the best matching locale from available locales
192
- const { localeData, availableLocales } = DurationFormat;
193
- const r = ResolveLocale(
194
- availableLocales,
195
- requestedLocales,
196
- opt,
197
- // [[RelevantExtensionKeys]] slot - only 'nu' (numbering system) is supported
198
- ["nu"],
199
- localeData,
200
- DurationFormat.getDefaultLocale
201
- );
202
- const locale = r.locale;
203
- // Initialize internal slots for this formatter instance
204
- const internalSlots = getInternalSlots(this);
205
- internalSlots.initializedDurationFormat = true;
206
- internalSlots.locale = locale;
207
- internalSlots.numberingSystem = r.nu;
208
- // Get overall formatting style: 'long' (3 hours), 'short' (3 hr), 'narrow' (3h), or 'digital' (3:00:00)
209
- const style = GetOption(opts, "style", "string", [
210
- "long",
211
- "short",
212
- "narrow",
213
- "digital"
214
- ], "short");
215
- internalSlots.style = style;
216
- internalSlots.dataLocale = r.dataLocale;
217
- // Process each duration unit (years through nanoseconds) to determine
218
- // its display style and when to show it (always/auto/never)
219
- let prevStyle = "";
220
- TABLE_3.forEach((row) => {
221
- const { styleSlot, displaySlot, unit, values: valueList, digitalDefault: digitalBase } = row;
222
- // Get the style and display options for this unit
223
- const unitOptions = GetDurationUnitOptions(unit, opts, style, valueList, digitalBase, prevStyle);
224
- internalSlots[styleSlot] = unitOptions.style;
225
- internalSlots[displaySlot] = unitOptions.display;
226
- // Track the previous style for time units (hours through microseconds)
227
- // This is used to ensure consistent digital formatting across related units
228
- if (unit === "hours" || unit === "minutes" || unit === "seconds" || unit === "milliseconds" || unit === "microseconds") {
229
- prevStyle = unitOptions.style;
230
- }
231
- });
232
- // Get the number of fractional digits for sub-second precision (0-9)
233
- internalSlots.fractionalDigits = GetNumberOption(opts, "fractionalDigits", 0, 9, undefined);
234
- }
235
- resolvedOptions() {
236
- if (typeof this !== "object" || !OrdinaryHasInstance(DurationFormat, this)) {
237
- throw TypeError("Method Intl.DurationFormat.prototype.resolvedOptions called on incompatible receiver");
238
- }
239
- const internalSlots = getInternalSlots(this);
240
- const ro = {};
241
- for (const key of RESOLVED_OPTIONS_KEYS) {
242
- let v = internalSlots[key];
243
- if (key === "fractionalDigits") {
244
- if (v !== undefined) {
245
- v = Number(v);
246
- }
247
- } else {
248
- invariant(v !== undefined, `Missing internal slot ${key}`);
249
- }
250
- ro[key] = v;
251
- }
252
- return ro;
253
- }
254
- formatToParts(duration) {
255
- const locInternalSlots = getInternalSlots(this);
256
- if (locInternalSlots.initializedDurationFormat === undefined) {
257
- throw new TypeError("Error uninitialized locale");
258
- }
259
- const record = ToDurationRecord(duration);
260
- const parts = PartitionDurationFormatPattern(this, record);
261
- const result = [];
262
- for (const { type, unit, value } of parts) {
263
- const obj = {
264
- type,
265
- value
266
- };
267
- if (unit) {
268
- obj.unit = unit;
269
- }
270
- result.push(obj);
271
- }
272
- return result;
273
- }
274
- format(duration) {
275
- const locInternalSlots = getInternalSlots(this);
276
- if (locInternalSlots.initializedDurationFormat === undefined) {
277
- throw new TypeError("Error uninitialized locale");
278
- }
279
- const record = ToDurationRecord(duration);
280
- const parts = PartitionDurationFormatPattern(this, record);
281
- let result = "";
282
- for (const { value } of parts) {
283
- result += value;
284
- }
285
- return result;
286
- }
287
- static supportedLocalesOf(locales, options) {
288
- return SupportedLocales(DurationFormat.availableLocales, CanonicalizeLocaleList(locales), options);
289
- }
290
- static __defaultLocale = "en";
291
- static availableLocales = new Set();
292
- static localeData = Object.keys(TIME_SEPARATORS.localeData).reduce((all, locale) => {
293
- DurationFormat.availableLocales.add(locale);
294
- const nu = TIME_SEPARATORS.localeData[locale].nu;
295
- all[locale] = {
296
- nu,
297
- digitalFormat: TIME_SEPARATORS.localeData[locale].separator || nu.reduce((separators, n) => {
298
- separators[n] = TIME_SEPARATORS.default;
299
- return separators;
300
- }, {})
301
- };
302
- return all;
303
- }, {});
304
- static getDefaultLocale = () => {
305
- return DurationFormat.__defaultLocale;
306
- };
307
- static polyfilled = true;
308
- }
@@ -1,2 +0,0 @@
1
- import type { DurationFormat, IntlDurationFormatInternal } from "./types.js";
2
- export declare function getInternalSlots(x: DurationFormat): IntlDurationFormatInternal;
@@ -1,9 +0,0 @@
1
- const internalSlotMap = new WeakMap();
2
- export function getInternalSlots(x) {
3
- let internalSlots = internalSlotMap.get(x);
4
- if (!internalSlots) {
5
- internalSlots = Object.create(null);
6
- internalSlotMap.set(x, internalSlots);
7
- }
8
- return internalSlots;
9
- }
@@ -1 +0,0 @@
1
- export declare const numberingSystemNames: ReadonlyArray<string>;