@formatjs/intl-durationformat 0.9.0 → 0.9.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.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +3 -3
- package/polyfill-force.js +9 -17
- package/polyfill.js +10 -18
- package/should-polyfill.js +1 -1
- package/src/abstract/DurationRecordSign.d.ts +1 -1
- package/src/abstract/DurationRecordSign.js +11 -11
- package/src/abstract/GetDurationUnitOptions.d.ts +2 -2
- package/src/abstract/GetDurationUnitOptions.js +34 -41
- package/src/abstract/IsValidDurationRecord.d.ts +1 -1
- package/src/abstract/IsValidDurationRecord.js +16 -16
- package/src/abstract/PartitionDurationFormatPattern.d.ts +2 -2
- package/src/abstract/PartitionDurationFormatPattern.js +127 -147
- package/src/abstract/ToDurationRecord.d.ts +1 -1
- package/src/abstract/ToDurationRecord.js +58 -66
- package/src/abstract/ToIntegerIfIntegral.js +4 -4
- package/src/constants.d.ts +60 -60
- package/src/constants.js +83 -82
- package/src/core.d.ts +15 -15
- package/src/core.js +298 -247
- package/src/get_internal_slots.d.ts +3 -1
- package/src/get_internal_slots.js +7 -7
- package/src/numbering-systems.generated.js +99 -1
- package/src/time-separators.generated.d.ts +2342 -2340
- package/src/time-separators.generated.js +809 -3905
- package/src/types.d.ts +91 -89
- package/src/types.js +0 -1
|
@@ -1,68 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import "../types.js";
|
|
2
|
+
import { IsValidDurationRecord } from "./IsValidDurationRecord.js";
|
|
3
|
+
import { ToIntegerIfIntegral } from "./ToIntegerIfIntegral.js";
|
|
3
4
|
export function ToDurationRecord(input) {
|
|
4
|
-
|
|
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
|
-
input.milliseconds === undefined &&
|
|
60
|
-
input.microseconds === undefined &&
|
|
61
|
-
input.nanoseconds === undefined) {
|
|
62
|
-
throw new TypeError('Invalid duration format');
|
|
63
|
-
}
|
|
64
|
-
if (!IsValidDurationRecord(result)) {
|
|
65
|
-
throw new RangeError('Invalid duration format');
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
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;
|
|
68
60
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { invariant, ToNumber } from
|
|
1
|
+
import { invariant, ToNumber } from "@formatjs/ecma402-abstract";
|
|
2
2
|
export function ToIntegerIfIntegral(arg) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const number = ToNumber(arg);
|
|
4
|
+
invariant(number.isInteger(), `${arg} is not an integer`);
|
|
5
|
+
return number.toNumber();
|
|
6
6
|
}
|
package/src/constants.d.ts
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { DurationRecord } from
|
|
1
|
+
import { type DurationRecord } from "./types.js";
|
|
2
2
|
export declare const TABLE_1: Array<keyof DurationRecord>;
|
|
3
3
|
export declare const TABLE_2: readonly [{
|
|
4
|
-
|
|
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
|
-
|
|
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
63
|
}];
|
package/src/constants.js
CHANGED
|
@@ -1,84 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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"
|
|
12
13
|
];
|
|
13
|
-
export
|
|
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
|
-
|
|
83
|
-
|
|
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
|
+
}
|
|
84
85
|
];
|
package/src/core.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { DurationFormatLocaleInternalData, DurationFormatPart, DurationFormat as DurationFormatType, DurationInput, ResolvedDurationFormatOptions } from
|
|
2
|
-
import { DurationFormatOptions } from
|
|
1
|
+
import type { DurationFormatLocaleInternalData, DurationFormatPart, DurationFormat as DurationFormatType, DurationInput, ResolvedDurationFormatOptions } from "./types.js";
|
|
2
|
+
import { type DurationFormatOptions } from "./types.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
* DurationFormat provides locale-sensitive duration formatting
|
|
5
|
+
* Implements the Intl.DurationFormat API from the TC39 proposal
|
|
6
|
+
*/
|
|
7
7
|
export declare class DurationFormat implements DurationFormatType {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
18
|
}
|