@formatjs/intl-durationformat 0.7.6 → 0.8.1
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 +10 -4
- 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/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src/core';
|
|
1
|
+
export * from './src/core.js';
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-durationformat",
|
|
3
3
|
"description": "Intl.DurationFormat polyfill",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Long Ho <holevietlong@gmail.com>",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"types": "index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./index.js",
|
|
11
|
+
"./polyfill.js": "./polyfill.js",
|
|
12
|
+
"./polyfill-force.js": "./polyfill-force.js",
|
|
13
|
+
"./should-polyfill.js": "./should-polyfill.js"
|
|
14
|
+
},
|
|
8
15
|
"dependencies": {
|
|
9
16
|
"tslib": "^2.8.0",
|
|
10
|
-
"@formatjs/ecma402-abstract": "
|
|
11
|
-
"@formatjs/intl-localematcher": "0.
|
|
17
|
+
"@formatjs/ecma402-abstract": "3.0.1",
|
|
18
|
+
"@formatjs/intl-localematcher": "0.7.1"
|
|
12
19
|
},
|
|
13
20
|
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
14
21
|
"homepage": "https://github.com/formatjs/formatjs#readme",
|
|
@@ -22,6 +29,5 @@
|
|
|
22
29
|
"react-intl",
|
|
23
30
|
"tc39"
|
|
24
31
|
],
|
|
25
|
-
"main": "index.js",
|
|
26
32
|
"repository": "formatjs/formatjs.git"
|
|
27
33
|
}
|
package/polyfill-force.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var _1 = require("./");
|
|
1
|
+
import { DurationFormat } from './index.js';
|
|
4
2
|
if (typeof Intl === 'undefined') {
|
|
5
3
|
if (typeof window !== 'undefined') {
|
|
6
4
|
Object.defineProperty(window, 'Intl', {
|
|
@@ -16,5 +14,5 @@ if (typeof Intl === 'undefined') {
|
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
Object.defineProperty(Intl, 'DurationFormat', {
|
|
19
|
-
value:
|
|
17
|
+
value: DurationFormat,
|
|
20
18
|
});
|
package/polyfill.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _1 = require("./");
|
|
4
|
-
var should_polyfill_1 = require("./should-polyfill");
|
|
1
|
+
import { DurationFormat } from './index.js';
|
|
2
|
+
import { shouldPolyfill } from './should-polyfill.js';
|
|
5
3
|
if (typeof Intl === 'undefined') {
|
|
6
4
|
if (typeof window !== 'undefined') {
|
|
7
5
|
Object.defineProperty(window, 'Intl', {
|
|
@@ -16,8 +14,8 @@ if (typeof Intl === 'undefined') {
|
|
|
16
14
|
});
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
|
-
if (
|
|
17
|
+
if (shouldPolyfill()) {
|
|
20
18
|
Object.defineProperty(Intl, 'DurationFormat', {
|
|
21
|
-
value:
|
|
19
|
+
value: DurationFormat,
|
|
22
20
|
});
|
|
23
21
|
}
|
package/should-polyfill.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DurationRecord } from '../types';
|
|
1
|
+
import { DurationRecord } from '../types.js';
|
|
2
2
|
export declare function DurationRecordSign(record: DurationRecord): -1 | 0 | 1;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var constants_1 = require("../constants");
|
|
5
|
-
function DurationRecordSign(record) {
|
|
6
|
-
for (var _i = 0, TABLE_1_1 = constants_1.TABLE_1; _i < TABLE_1_1.length; _i++) {
|
|
1
|
+
import { TABLE_1 } from '../constants.js';
|
|
2
|
+
export function DurationRecordSign(record) {
|
|
3
|
+
for (var _i = 0, TABLE_1_1 = TABLE_1; _i < TABLE_1_1.length; _i++) {
|
|
7
4
|
var key = TABLE_1_1[_i];
|
|
8
5
|
if (record[key] < 0) {
|
|
9
6
|
return -1;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
5
|
-
function GetDurationUnitOptions(unit, options, baseStyle, stylesList, digitalBase, prevStyle) {
|
|
6
|
-
var style = (0, ecma402_abstract_1.GetOption)(options, unit, 'string', stylesList, undefined);
|
|
1
|
+
import { GetOption } from '@formatjs/ecma402-abstract';
|
|
2
|
+
export function GetDurationUnitOptions(unit, options, baseStyle, stylesList, digitalBase, prevStyle) {
|
|
3
|
+
var style = GetOption(options, unit, 'string', stylesList, undefined);
|
|
7
4
|
var displayDefault = 'always';
|
|
8
5
|
if (style === undefined) {
|
|
9
6
|
if (baseStyle === 'digital') {
|
|
@@ -23,7 +20,7 @@ function GetDurationUnitOptions(unit, options, baseStyle, stylesList, digitalBas
|
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
var displayField = "".concat(unit, "Display");
|
|
26
|
-
var display =
|
|
23
|
+
var display = GetOption(options, displayField, 'string', ['always', 'auto'], displayDefault);
|
|
27
24
|
if (prevStyle === 'numeric' || prevStyle === '2-digit') {
|
|
28
25
|
if (style !== 'numeric' && style !== '2-digit') {
|
|
29
26
|
throw new RangeError("Can't mix numeric and non-numeric styles");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DurationRecord } from '../types';
|
|
1
|
+
import { DurationRecord } from '../types.js';
|
|
2
2
|
export declare function IsValidDurationRecord(record: DurationRecord): boolean;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
function IsValidDurationRecord(record) {
|
|
8
|
-
var sign = (0, DurationRecordSign_1.DurationRecordSign)(record);
|
|
9
|
-
for (var _i = 0, TABLE_1_1 = constants_1.TABLE_1; _i < TABLE_1_1.length; _i++) {
|
|
1
|
+
import { invariant } from '@formatjs/ecma402-abstract';
|
|
2
|
+
import { TABLE_1 } from '../constants.js';
|
|
3
|
+
import { DurationRecordSign } from './DurationRecordSign.js';
|
|
4
|
+
export function IsValidDurationRecord(record) {
|
|
5
|
+
var sign = DurationRecordSign(record);
|
|
6
|
+
for (var _i = 0, TABLE_1_1 = TABLE_1; _i < TABLE_1_1.length; _i++) {
|
|
10
7
|
var key = TABLE_1_1[_i];
|
|
11
8
|
var v = record[key];
|
|
12
|
-
|
|
9
|
+
invariant(isFinite(Number(v)), "".concat(key, " is not finite"));
|
|
13
10
|
if (v < 0 && sign > 0) {
|
|
14
11
|
return false;
|
|
15
12
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DurationFormat } from '../core';
|
|
2
|
-
import { DurationFormatPart, DurationRecord } from '../types';
|
|
1
|
+
import { DurationFormat } from '../core.js';
|
|
2
|
+
import { DurationFormatPart, DurationRecord } from '../types.js';
|
|
3
3
|
export declare function PartitionDurationFormatPattern(df: DurationFormat, duration: DurationRecord): DurationFormatPart[];
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var core_1 = require("../core");
|
|
7
|
-
var get_internal_slots_1 = require("../get_internal_slots");
|
|
8
|
-
function PartitionDurationFormatPattern(df, duration) {
|
|
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
|
+
export function PartitionDurationFormatPattern(df, duration) {
|
|
9
6
|
var result = [];
|
|
10
7
|
var done = false;
|
|
11
8
|
var separated = false;
|
|
12
|
-
var internalSlots =
|
|
9
|
+
var internalSlots = getInternalSlots(df);
|
|
13
10
|
var dataLocale = internalSlots.dataLocale;
|
|
14
|
-
var dataLocaleData =
|
|
11
|
+
var dataLocaleData = DurationFormat.localeData[dataLocale];
|
|
15
12
|
if (!dataLocaleData) {
|
|
16
13
|
throw new TypeError('Invalid locale');
|
|
17
14
|
}
|
|
18
15
|
var numberingSystem = internalSlots.numberingSystem;
|
|
19
16
|
var separator = dataLocaleData.digitalFormat[numberingSystem];
|
|
20
17
|
var _loop_1 = function (i) {
|
|
21
|
-
var row =
|
|
18
|
+
var row = TABLE_2[i];
|
|
22
19
|
var value = duration[row.valueField];
|
|
23
20
|
var style = internalSlots[row.styleSlot];
|
|
24
21
|
var display = internalSlots[row.displaySlot];
|
|
@@ -72,7 +69,7 @@ function PartitionDurationFormatPattern(df, duration) {
|
|
|
72
69
|
nfOpts.unit = numberFormatUnit;
|
|
73
70
|
nfOpts.unitDisplay = style;
|
|
74
71
|
}
|
|
75
|
-
var nf =
|
|
72
|
+
var nf = createMemoizedNumberFormat(internalSlots.locale, nfOpts);
|
|
76
73
|
var list_1;
|
|
77
74
|
if (!separated) {
|
|
78
75
|
list_1 = [];
|
|
@@ -104,7 +101,7 @@ function PartitionDurationFormatPattern(df, duration) {
|
|
|
104
101
|
separated = false;
|
|
105
102
|
}
|
|
106
103
|
};
|
|
107
|
-
for (var i = 0; i <
|
|
104
|
+
for (var i = 0; i < TABLE_2.length && !done; i++) {
|
|
108
105
|
_loop_1(i);
|
|
109
106
|
}
|
|
110
107
|
var lfOpts = Object.create(null);
|
|
@@ -114,7 +111,7 @@ function PartitionDurationFormatPattern(df, duration) {
|
|
|
114
111
|
listStyle = 'short';
|
|
115
112
|
}
|
|
116
113
|
lfOpts.style = listStyle;
|
|
117
|
-
var lf =
|
|
114
|
+
var lf = createMemoizedListFormat(internalSlots.locale, lfOpts);
|
|
118
115
|
var strings = [];
|
|
119
116
|
for (var _i = 0, result_1 = result; _i < result_1.length; _i++) {
|
|
120
117
|
var parts = result_1[_i];
|
|
@@ -132,7 +129,7 @@ function PartitionDurationFormatPattern(df, duration) {
|
|
|
132
129
|
for (var _b = 0, formatted_1 = formatted; _b < formatted_1.length; _b++) {
|
|
133
130
|
var _c = formatted_1[_b], type = _c.type, value = _c.value;
|
|
134
131
|
if (type === 'element') {
|
|
135
|
-
|
|
132
|
+
invariant(resultIndex < resultLength, 'Index out of bounds');
|
|
136
133
|
var parts = result[resultIndex];
|
|
137
134
|
for (var _d = 0, parts_2 = parts; _d < parts_2.length; _d++) {
|
|
138
135
|
var part = parts_2[_d];
|
|
@@ -141,7 +138,7 @@ function PartitionDurationFormatPattern(df, duration) {
|
|
|
141
138
|
resultIndex++;
|
|
142
139
|
}
|
|
143
140
|
else {
|
|
144
|
-
|
|
141
|
+
invariant(type === 'literal', 'Type must be literal');
|
|
145
142
|
flattened.push({
|
|
146
143
|
type: 'literal',
|
|
147
144
|
value: value,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DurationInput, DurationRecord } from '../types';
|
|
1
|
+
import { DurationInput, DurationRecord } from '../types.js';
|
|
2
2
|
export declare function ToDurationRecord(input: DurationInput): DurationRecord;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var IsValidDurationRecord_1 = require("./IsValidDurationRecord");
|
|
5
|
-
var ToIntegerIfIntegral_1 = require("./ToIntegerIfIntegral");
|
|
6
|
-
function ToDurationRecord(input) {
|
|
1
|
+
import { IsValidDurationRecord } from './IsValidDurationRecord.js';
|
|
2
|
+
import { ToIntegerIfIntegral } from './ToIntegerIfIntegral.js';
|
|
3
|
+
export function ToDurationRecord(input) {
|
|
7
4
|
if (typeof input !== 'object') {
|
|
8
5
|
if (typeof input === 'string') {
|
|
9
6
|
throw new RangeError('Invalid duration format');
|
|
@@ -23,34 +20,34 @@ function ToDurationRecord(input) {
|
|
|
23
20
|
nanoseconds: 0,
|
|
24
21
|
};
|
|
25
22
|
if (input.days !== undefined) {
|
|
26
|
-
result.days =
|
|
23
|
+
result.days = ToIntegerIfIntegral(input.days);
|
|
27
24
|
}
|
|
28
25
|
if (input.hours !== undefined) {
|
|
29
|
-
result.hours =
|
|
26
|
+
result.hours = ToIntegerIfIntegral(input.hours);
|
|
30
27
|
}
|
|
31
28
|
if (input.microseconds !== undefined) {
|
|
32
|
-
result.microseconds =
|
|
29
|
+
result.microseconds = ToIntegerIfIntegral(input.microseconds);
|
|
33
30
|
}
|
|
34
31
|
if (input.milliseconds !== undefined) {
|
|
35
|
-
result.milliseconds =
|
|
32
|
+
result.milliseconds = ToIntegerIfIntegral(input.milliseconds);
|
|
36
33
|
}
|
|
37
34
|
if (input.minutes !== undefined) {
|
|
38
|
-
result.minutes =
|
|
35
|
+
result.minutes = ToIntegerIfIntegral(input.minutes);
|
|
39
36
|
}
|
|
40
37
|
if (input.months !== undefined) {
|
|
41
|
-
result.months =
|
|
38
|
+
result.months = ToIntegerIfIntegral(input.months);
|
|
42
39
|
}
|
|
43
40
|
if (input.nanoseconds !== undefined) {
|
|
44
|
-
result.nanoseconds =
|
|
41
|
+
result.nanoseconds = ToIntegerIfIntegral(input.nanoseconds);
|
|
45
42
|
}
|
|
46
43
|
if (input.seconds !== undefined) {
|
|
47
|
-
result.seconds =
|
|
44
|
+
result.seconds = ToIntegerIfIntegral(input.seconds);
|
|
48
45
|
}
|
|
49
46
|
if (input.weeks !== undefined) {
|
|
50
|
-
result.weeks =
|
|
47
|
+
result.weeks = ToIntegerIfIntegral(input.weeks);
|
|
51
48
|
}
|
|
52
49
|
if (input.years !== undefined) {
|
|
53
|
-
result.years =
|
|
50
|
+
result.years = ToIntegerIfIntegral(input.years);
|
|
54
51
|
}
|
|
55
52
|
if (input.years === undefined &&
|
|
56
53
|
input.months === undefined &&
|
|
@@ -64,7 +61,7 @@ function ToDurationRecord(input) {
|
|
|
64
61
|
input.nanoseconds === undefined) {
|
|
65
62
|
throw new TypeError('Invalid duration format');
|
|
66
63
|
}
|
|
67
|
-
if (!
|
|
64
|
+
if (!IsValidDurationRecord(result)) {
|
|
68
65
|
throw new RangeError('Invalid duration format');
|
|
69
66
|
}
|
|
70
67
|
return result;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function ToIntegerIfIntegral(arg) {
|
|
6
|
-
var number = (0, ecma402_abstract_1.ToNumber)(arg);
|
|
7
|
-
(0, ecma402_abstract_1.invariant)(number.isInteger(), "".concat(arg, " is not an integer"));
|
|
1
|
+
import { invariant, ToNumber } from '@formatjs/ecma402-abstract';
|
|
2
|
+
export function ToIntegerIfIntegral(arg) {
|
|
3
|
+
var number = ToNumber(arg);
|
|
4
|
+
invariant(number.isInteger(), "".concat(arg, " is not an integer"));
|
|
8
5
|
return number.toNumber();
|
|
9
6
|
}
|
package/src/constants.d.ts
CHANGED
package/src/constants.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TABLE_2 = exports.TABLE_1 = void 0;
|
|
4
|
-
exports.TABLE_1 = [
|
|
1
|
+
export var TABLE_1 = [
|
|
5
2
|
'years',
|
|
6
3
|
'months',
|
|
7
4
|
'weeks',
|
|
@@ -13,7 +10,7 @@ exports.TABLE_1 = [
|
|
|
13
10
|
'microseconds',
|
|
14
11
|
'nanoseconds',
|
|
15
12
|
];
|
|
16
|
-
|
|
13
|
+
export var TABLE_2 = [
|
|
17
14
|
{
|
|
18
15
|
valueField: 'years',
|
|
19
16
|
styleSlot: 'years',
|
package/src/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DurationFormatLocaleInternalData, DurationFormatPart, DurationFormat as DurationFormatType, DurationInput, ResolvedDurationFormatOptions } from './types';
|
|
2
|
-
import { DurationFormatOptions } from './types';
|
|
1
|
+
import type { DurationFormatLocaleInternalData, DurationFormatPart, DurationFormat as DurationFormatType, DurationInput, ResolvedDurationFormatOptions } from './types.js';
|
|
2
|
+
import { DurationFormatOptions } from './types.js';
|
|
3
3
|
export declare class DurationFormat implements DurationFormatType {
|
|
4
4
|
constructor(locales?: string | string[], options?: DurationFormatOptions);
|
|
5
5
|
resolvedOptions(): ResolvedDurationFormatOptions;
|
package/src/core.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var get_internal_slots_1 = require("./get_internal_slots");
|
|
10
|
-
var numbering_systems_generated_1 = require("./numbering-systems.generated");
|
|
11
|
-
var time_separators_generated_1 = require("./time-separators.generated");
|
|
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.js';
|
|
4
|
+
import { PartitionDurationFormatPattern } from './abstract/PartitionDurationFormatPattern.js';
|
|
5
|
+
import { ToDurationRecord } from './abstract/ToDurationRecord.js';
|
|
6
|
+
import { getInternalSlots } from './get_internal_slots.js';
|
|
7
|
+
import { numberingSystemNames } from './numbering-systems.generated.js';
|
|
8
|
+
import { TIME_SEPARATORS } from './time-separators.generated.js';
|
|
12
9
|
var RESOLVED_OPTIONS_KEYS = [
|
|
13
10
|
'locale',
|
|
14
11
|
'style',
|
|
@@ -115,13 +112,13 @@ var DurationFormat = /** @class */ (function () {
|
|
|
115
112
|
if (!newTarget) {
|
|
116
113
|
throw new TypeError("Intl.DurationFormat must be called with 'new'");
|
|
117
114
|
}
|
|
118
|
-
var requestedLocales =
|
|
115
|
+
var requestedLocales = CanonicalizeLocaleList(locales);
|
|
119
116
|
var opt = Object.create(null);
|
|
120
|
-
var opts = options === undefined ? Object.create(null) :
|
|
121
|
-
var matcher =
|
|
122
|
-
var numberingSystem =
|
|
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);
|
|
123
120
|
if (numberingSystem !== undefined &&
|
|
124
|
-
|
|
121
|
+
numberingSystemNames.indexOf(numberingSystem) < 0) {
|
|
125
122
|
// 8.a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal,
|
|
126
123
|
// throw a RangeError exception.
|
|
127
124
|
throw RangeError("Invalid numberingSystems: ".concat(numberingSystem));
|
|
@@ -129,21 +126,21 @@ var DurationFormat = /** @class */ (function () {
|
|
|
129
126
|
opt.nu = numberingSystem;
|
|
130
127
|
opt.localeMatcher = matcher;
|
|
131
128
|
var localeData = DurationFormat.localeData, availableLocales = DurationFormat.availableLocales;
|
|
132
|
-
var r =
|
|
129
|
+
var r = ResolveLocale(availableLocales, requestedLocales, opt,
|
|
133
130
|
// [[RelevantExtensionKeys]] slot, which is a constant
|
|
134
131
|
['nu'], localeData, DurationFormat.getDefaultLocale);
|
|
135
132
|
var locale = r.locale;
|
|
136
|
-
var internalSlots =
|
|
133
|
+
var internalSlots = getInternalSlots(this);
|
|
137
134
|
internalSlots.initializedDurationFormat = true;
|
|
138
135
|
internalSlots.locale = locale;
|
|
139
136
|
internalSlots.numberingSystem = r.nu;
|
|
140
|
-
var style =
|
|
137
|
+
var style = GetOption(opts, 'style', 'string', ['long', 'short', 'narrow', 'digital'], 'short');
|
|
141
138
|
internalSlots.style = style;
|
|
142
139
|
internalSlots.dataLocale = r.dataLocale;
|
|
143
140
|
var prevStyle = '';
|
|
144
141
|
TABLE_3.forEach(function (row) {
|
|
145
142
|
var styleSlot = row.styleSlot, displaySlot = row.displaySlot, unit = row.unit, valueList = row.values, digitalBase = row.digitalDefault;
|
|
146
|
-
var unitOptions =
|
|
143
|
+
var unitOptions = GetDurationUnitOptions(unit, opts, style, valueList, digitalBase, prevStyle);
|
|
147
144
|
internalSlots[styleSlot] = unitOptions.style;
|
|
148
145
|
internalSlots[displaySlot] = unitOptions.display;
|
|
149
146
|
if (unit === 'hours' ||
|
|
@@ -154,14 +151,14 @@ var DurationFormat = /** @class */ (function () {
|
|
|
154
151
|
prevStyle = unitOptions.style;
|
|
155
152
|
}
|
|
156
153
|
});
|
|
157
|
-
internalSlots.fractionalDigits =
|
|
154
|
+
internalSlots.fractionalDigits = GetNumberOption(opts, 'fractionalDigits', 0, 9, undefined);
|
|
158
155
|
}
|
|
159
156
|
DurationFormat.prototype.resolvedOptions = function () {
|
|
160
157
|
if (typeof this !== 'object' ||
|
|
161
|
-
!
|
|
158
|
+
!OrdinaryHasInstance(DurationFormat, this)) {
|
|
162
159
|
throw TypeError('Method Intl.DurationFormat.prototype.resolvedOptions called on incompatible receiver');
|
|
163
160
|
}
|
|
164
|
-
var internalSlots =
|
|
161
|
+
var internalSlots = getInternalSlots(this);
|
|
165
162
|
var ro = {};
|
|
166
163
|
for (var _i = 0, RESOLVED_OPTIONS_KEYS_1 = RESOLVED_OPTIONS_KEYS; _i < RESOLVED_OPTIONS_KEYS_1.length; _i++) {
|
|
167
164
|
var key = RESOLVED_OPTIONS_KEYS_1[_i];
|
|
@@ -172,20 +169,19 @@ var DurationFormat = /** @class */ (function () {
|
|
|
172
169
|
}
|
|
173
170
|
}
|
|
174
171
|
else {
|
|
175
|
-
|
|
172
|
+
invariant(v !== undefined, "Missing internal slot ".concat(key));
|
|
176
173
|
}
|
|
177
174
|
ro[key] = v;
|
|
178
175
|
}
|
|
179
176
|
return ro;
|
|
180
177
|
};
|
|
181
178
|
DurationFormat.prototype.formatToParts = function (duration) {
|
|
182
|
-
var
|
|
183
|
-
var locInternalSlots = (0, get_internal_slots_1.getInternalSlots)(this);
|
|
179
|
+
var locInternalSlots = getInternalSlots(this);
|
|
184
180
|
if (locInternalSlots.initializedDurationFormat === undefined) {
|
|
185
181
|
throw new TypeError('Error uninitialized locale');
|
|
186
182
|
}
|
|
187
|
-
var record =
|
|
188
|
-
var parts =
|
|
183
|
+
var record = ToDurationRecord(duration);
|
|
184
|
+
var parts = PartitionDurationFormatPattern(this, record);
|
|
189
185
|
var result = [];
|
|
190
186
|
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
191
187
|
var _a = parts_1[_i], type = _a.type, unit = _a.unit, value = _a.value;
|
|
@@ -198,13 +194,12 @@ var DurationFormat = /** @class */ (function () {
|
|
|
198
194
|
return result;
|
|
199
195
|
};
|
|
200
196
|
DurationFormat.prototype.format = function (duration) {
|
|
201
|
-
var
|
|
202
|
-
var locInternalSlots = (0, get_internal_slots_1.getInternalSlots)(this);
|
|
197
|
+
var locInternalSlots = getInternalSlots(this);
|
|
203
198
|
if (locInternalSlots.initializedDurationFormat === undefined) {
|
|
204
199
|
throw new TypeError('Error uninitialized locale');
|
|
205
200
|
}
|
|
206
|
-
var record =
|
|
207
|
-
var parts =
|
|
201
|
+
var record = ToDurationRecord(duration);
|
|
202
|
+
var parts = PartitionDurationFormatPattern(this, record);
|
|
208
203
|
var result = '';
|
|
209
204
|
for (var _i = 0, parts_2 = parts; _i < parts_2.length; _i++) {
|
|
210
205
|
var value = parts_2[_i].value;
|
|
@@ -213,18 +208,18 @@ var DurationFormat = /** @class */ (function () {
|
|
|
213
208
|
return result;
|
|
214
209
|
};
|
|
215
210
|
DurationFormat.supportedLocalesOf = function (locales, options) {
|
|
216
|
-
return
|
|
211
|
+
return SupportedLocales(DurationFormat.availableLocales, CanonicalizeLocaleList(locales), options);
|
|
217
212
|
};
|
|
218
213
|
DurationFormat.__defaultLocale = 'en';
|
|
219
214
|
DurationFormat.availableLocales = new Set();
|
|
220
|
-
DurationFormat.localeData = Object.keys(
|
|
215
|
+
DurationFormat.localeData = Object.keys(TIME_SEPARATORS.localeData).reduce(function (all, locale) {
|
|
221
216
|
DurationFormat.availableLocales.add(locale);
|
|
222
|
-
var nu =
|
|
217
|
+
var nu = TIME_SEPARATORS.localeData[locale].nu;
|
|
223
218
|
all[locale] = {
|
|
224
219
|
nu: nu,
|
|
225
|
-
digitalFormat:
|
|
220
|
+
digitalFormat: TIME_SEPARATORS.localeData[locale].separator ||
|
|
226
221
|
nu.reduce(function (separators, n) {
|
|
227
|
-
separators[n] =
|
|
222
|
+
separators[n] = TIME_SEPARATORS.default;
|
|
228
223
|
return separators;
|
|
229
224
|
}, {}),
|
|
230
225
|
};
|
|
@@ -236,4 +231,4 @@ var DurationFormat = /** @class */ (function () {
|
|
|
236
231
|
DurationFormat.polyfilled = true;
|
|
237
232
|
return DurationFormat;
|
|
238
233
|
}());
|
|
239
|
-
|
|
234
|
+
export { DurationFormat };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { DurationFormat, IntlDurationFormatInternal } from './types';
|
|
1
|
+
import type { DurationFormat, IntlDurationFormatInternal } from './types.js';
|
|
2
2
|
export declare function getInternalSlots(x: DurationFormat): IntlDurationFormatInternal;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInternalSlots = getInternalSlots;
|
|
4
1
|
var internalSlotMap = new WeakMap();
|
|
5
|
-
function getInternalSlots(x) {
|
|
2
|
+
export function getInternalSlots(x) {
|
|
6
3
|
var internalSlots = internalSlotMap.get(x);
|
|
7
4
|
if (!internalSlots) {
|
|
8
5
|
internalSlots = Object.create(null);
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.numberingSystemNames = void 0;
|
|
4
|
-
exports.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"];
|
|
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"];
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TIME_SEPARATORS = void 0;
|
|
4
1
|
/* @generated */
|
|
5
2
|
// prettier-ignore
|
|
6
|
-
|
|
3
|
+
export var TIME_SEPARATORS = {
|
|
7
4
|
"default": ":",
|
|
8
5
|
"localeData": {
|
|
9
6
|
"aa": {
|
package/src/types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface ResolvedDurationFormatOptions {
|
|
|
10
10
|
weeksDisplay: 'always' | 'auto';
|
|
11
11
|
days: 'long' | 'short' | 'narrow';
|
|
12
12
|
daysDisplay: 'always' | 'auto';
|
|
13
|
-
hours: 'long' | 'short' | 'narrow' | 'numeric';
|
|
13
|
+
hours: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
14
14
|
hoursDisplay: 'always' | 'auto';
|
|
15
15
|
minutes: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
16
16
|
minutesDisplay: 'always' | 'auto';
|
|
@@ -59,7 +59,7 @@ export interface IntlDurationFormatInternal {
|
|
|
59
59
|
weeksDisplay: 'always' | 'auto';
|
|
60
60
|
days: 'long' | 'short' | 'narrow';
|
|
61
61
|
daysDisplay: 'always' | 'auto';
|
|
62
|
-
hours: 'long' | 'short' | 'narrow' | 'numeric';
|
|
62
|
+
hours: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
63
63
|
hoursDisplay: 'always' | 'auto';
|
|
64
64
|
minutes: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
65
65
|
minutesDisplay: 'always' | 'auto';
|
package/src/types.js
CHANGED
package/lib/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src/core';
|
package/lib/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src/core';
|
package/lib/polyfill-force.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/polyfill-force.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { DurationFormat } from './';
|
|
2
|
-
if (typeof Intl === 'undefined') {
|
|
3
|
-
if (typeof window !== 'undefined') {
|
|
4
|
-
Object.defineProperty(window, 'Intl', {
|
|
5
|
-
value: {},
|
|
6
|
-
});
|
|
7
|
-
// @ts-ignore we don't include @types/node so global isn't a thing
|
|
8
|
-
}
|
|
9
|
-
else if (typeof global !== 'undefined') {
|
|
10
|
-
// @ts-ignore we don't include @types/node so global isn't a thing
|
|
11
|
-
Object.defineProperty(global, 'Intl', {
|
|
12
|
-
value: {},
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(Intl, 'DurationFormat', {
|
|
17
|
-
value: DurationFormat,
|
|
18
|
-
});
|
package/lib/polyfill.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|