@formatjs/intl-durationformat 0.2.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/LICENSE.md +9 -0
- package/README.md +3 -0
- package/index.d.ts +1 -0
- package/index.js +4 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/polyfill-force.d.ts +1 -0
- package/lib/polyfill-force.js +18 -0
- package/lib/polyfill.d.ts +1 -0
- package/lib/polyfill.js +21 -0
- package/lib/should-polyfill.d.ts +1 -0
- package/lib/should-polyfill.js +3 -0
- package/lib/src/abstract/DurationRecordSign.d.ts +2 -0
- package/lib/src/abstract/DurationRecordSign.js +13 -0
- package/lib/src/abstract/GetDurationUnitOptions.d.ts +4 -0
- package/lib/src/abstract/GetDurationUnitOptions.js +43 -0
- package/lib/src/abstract/IsValidDurationRecord.d.ts +2 -0
- package/lib/src/abstract/IsValidDurationRecord.js +18 -0
- package/lib/src/abstract/PartitionDurationFormatPattern.d.ts +3 -0
- package/lib/src/abstract/PartitionDurationFormatPattern.js +149 -0
- package/lib/src/abstract/ToDurationRecord.d.ts +2 -0
- package/lib/src/abstract/ToDurationRecord.js +68 -0
- package/lib/src/abstract/ToIntegerIfIntegral.d.ts +1 -0
- package/lib/src/abstract/ToIntegerIfIntegral.js +8 -0
- package/lib/src/constants.d.ts +63 -0
- package/lib/src/constants.js +84 -0
- package/lib/src/core.d.ts +14 -0
- package/lib/src/core.js +236 -0
- package/lib/src/get_internal_slots.d.ts +2 -0
- package/lib/src/get_internal_slots.js +9 -0
- package/lib/src/numbering-systems.generated.d.ts +1 -0
- package/lib/src/numbering-systems.generated.js +1 -0
- package/lib/src/time-separators.generated.d.ts +2123 -0
- package/lib/src/time-separators.generated.js +3541 -0
- package/lib/src/types.d.ts +108 -0
- package/lib/src/types.js +2 -0
- package/package.json +32 -0
- package/polyfill-force.d.ts +1 -0
- package/polyfill-force.js +20 -0
- package/polyfill.d.ts +1 -0
- package/polyfill.js +23 -0
- package/should-polyfill.d.ts +1 -0
- package/should-polyfill.js +7 -0
- package/src/abstract/DurationRecordSign.d.ts +2 -0
- package/src/abstract/DurationRecordSign.js +17 -0
- package/src/abstract/GetDurationUnitOptions.d.ts +4 -0
- package/src/abstract/GetDurationUnitOptions.js +47 -0
- package/src/abstract/IsValidDurationRecord.d.ts +2 -0
- package/src/abstract/IsValidDurationRecord.js +22 -0
- package/src/abstract/PartitionDurationFormatPattern.d.ts +3 -0
- package/src/abstract/PartitionDurationFormatPattern.js +153 -0
- package/src/abstract/ToDurationRecord.d.ts +2 -0
- package/src/abstract/ToDurationRecord.js +72 -0
- package/src/abstract/ToIntegerIfIntegral.d.ts +1 -0
- package/src/abstract/ToIntegerIfIntegral.js +12 -0
- package/src/constants.d.ts +63 -0
- package/src/constants.js +87 -0
- package/src/core.d.ts +14 -0
- package/src/core.js +239 -0
- package/src/get_internal_slots.d.ts +2 -0
- package/src/get_internal_slots.js +13 -0
- package/src/numbering-systems.generated.d.ts +1 -0
- package/src/numbering-systems.generated.js +4 -0
- package/src/time-separators.generated.d.ts +2123 -0
- package/src/time-separators.generated.js +3544 -0
- package/src/types.d.ts +108 -0
- package/src/types.js +3 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export type DurationFormatOptions = Partial<ResolvedDurationFormatOptions>;
|
|
2
|
+
export interface ResolvedDurationFormatOptions {
|
|
3
|
+
localeMatcher: 'best fit' | 'lookup';
|
|
4
|
+
style: 'long' | 'short' | 'narrow' | 'digital';
|
|
5
|
+
years: 'long' | 'short' | 'narrow';
|
|
6
|
+
yearsDisplay: 'always' | 'auto';
|
|
7
|
+
months: 'long' | 'short' | 'narrow';
|
|
8
|
+
monthsDisplay: 'always' | 'auto';
|
|
9
|
+
weeks: 'long' | 'short' | 'narrow';
|
|
10
|
+
weeksDisplay: 'always' | 'auto';
|
|
11
|
+
days: 'long' | 'short' | 'narrow';
|
|
12
|
+
daysDisplay: 'always' | 'auto';
|
|
13
|
+
hours: 'long' | 'short' | 'narrow' | 'numeric';
|
|
14
|
+
hoursDisplay: 'always' | 'auto';
|
|
15
|
+
minutes: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
16
|
+
minutesDisplay: 'always' | 'auto';
|
|
17
|
+
seconds: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
18
|
+
secondsDisplay: 'always' | 'auto';
|
|
19
|
+
milliseconds: 'long' | 'short' | 'narrow' | 'numeric';
|
|
20
|
+
millisecondsDisplay: 'always' | 'auto';
|
|
21
|
+
microseconds: 'long' | 'short' | 'narrow' | 'numeric';
|
|
22
|
+
microsecondsDisplay: 'always' | 'auto';
|
|
23
|
+
nanoseconds: 'long' | 'short' | 'narrow' | 'numeric';
|
|
24
|
+
nanosecondsDisplay: 'always' | 'auto';
|
|
25
|
+
fractionalDigits?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
26
|
+
numberingSystem: string;
|
|
27
|
+
round: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface DurationFormatPart {
|
|
30
|
+
unit?: string;
|
|
31
|
+
type: unknown;
|
|
32
|
+
value: string;
|
|
33
|
+
}
|
|
34
|
+
export interface RawDurationLocaleData {
|
|
35
|
+
data: DurationFormatLocaleInternalData;
|
|
36
|
+
locale: string;
|
|
37
|
+
}
|
|
38
|
+
export interface DurationFormatLocaleInternalData {
|
|
39
|
+
nu: readonly string[];
|
|
40
|
+
digitalFormat: Record<string, string>;
|
|
41
|
+
}
|
|
42
|
+
export interface DurationFormat {
|
|
43
|
+
resolvedOptions(): ResolvedDurationFormatOptions;
|
|
44
|
+
formatToParts(duration: DurationInput): DurationFormatPart[];
|
|
45
|
+
format(duration: DurationInput): string;
|
|
46
|
+
}
|
|
47
|
+
export interface IntlDurationFormatInternal {
|
|
48
|
+
initializedDurationFormat: boolean;
|
|
49
|
+
fractionalDigits: number | undefined;
|
|
50
|
+
dataLocale: string;
|
|
51
|
+
locale: string;
|
|
52
|
+
numberingSystem: string;
|
|
53
|
+
style: DurationFormatOptions['style'];
|
|
54
|
+
years: 'long' | 'short' | 'narrow';
|
|
55
|
+
yearsDisplay: 'always' | 'auto';
|
|
56
|
+
months: 'long' | 'short' | 'narrow';
|
|
57
|
+
monthsDisplay: 'always' | 'auto';
|
|
58
|
+
weeks: 'long' | 'short' | 'narrow';
|
|
59
|
+
weeksDisplay: 'always' | 'auto';
|
|
60
|
+
days: 'long' | 'short' | 'narrow';
|
|
61
|
+
daysDisplay: 'always' | 'auto';
|
|
62
|
+
hours: 'long' | 'short' | 'narrow' | 'numeric';
|
|
63
|
+
hoursDisplay: 'always' | 'auto';
|
|
64
|
+
minutes: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
65
|
+
minutesDisplay: 'always' | 'auto';
|
|
66
|
+
seconds: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
67
|
+
secondsDisplay: 'always' | 'auto';
|
|
68
|
+
milliseconds: 'long' | 'short' | 'narrow' | 'numeric';
|
|
69
|
+
millisecondsDisplay: 'always' | 'auto';
|
|
70
|
+
microseconds: 'long' | 'short' | 'narrow' | 'numeric';
|
|
71
|
+
microsecondsDisplay: 'always' | 'auto';
|
|
72
|
+
nanoseconds: 'long' | 'short' | 'narrow' | 'numeric';
|
|
73
|
+
nanosecondsDisplay: 'always' | 'auto';
|
|
74
|
+
}
|
|
75
|
+
export interface DurationInput {
|
|
76
|
+
years?: number;
|
|
77
|
+
months?: number;
|
|
78
|
+
weeks?: number;
|
|
79
|
+
days?: number;
|
|
80
|
+
hours?: number;
|
|
81
|
+
minutes?: number;
|
|
82
|
+
seconds?: number;
|
|
83
|
+
milliseconds?: number;
|
|
84
|
+
microseconds?: number;
|
|
85
|
+
nanoseconds?: number;
|
|
86
|
+
}
|
|
87
|
+
export interface DurationRecord {
|
|
88
|
+
years: number;
|
|
89
|
+
months: number;
|
|
90
|
+
weeks: number;
|
|
91
|
+
days: number;
|
|
92
|
+
hours: number;
|
|
93
|
+
minutes: number;
|
|
94
|
+
seconds: number;
|
|
95
|
+
milliseconds: number;
|
|
96
|
+
microseconds: number;
|
|
97
|
+
nanoseconds: number;
|
|
98
|
+
}
|
|
99
|
+
export interface DurationFormatConstructor {
|
|
100
|
+
new (locales?: string | string[], options?: DurationFormatOptions): DurationFormat;
|
|
101
|
+
(locales?: string | string[], options?: DurationFormatOptions): DurationFormat;
|
|
102
|
+
supportedLocalesOf(locales: string | string[], options?: Pick<DurationFormatOptions, 'localeMatcher'>): string[];
|
|
103
|
+
getDefaultLocale(): string;
|
|
104
|
+
__defaultLocale: string;
|
|
105
|
+
localeData: Record<string, DurationFormatLocaleInternalData | undefined>;
|
|
106
|
+
availableLocales: Set<string>;
|
|
107
|
+
polyfilled: boolean;
|
|
108
|
+
}
|
package/lib/src/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@formatjs/intl-durationformat",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Intl.DurationFormat polyfill",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"intl",
|
|
7
|
+
"durationformat",
|
|
8
|
+
"duration",
|
|
9
|
+
"formatjs",
|
|
10
|
+
"react-intl",
|
|
11
|
+
"i18n",
|
|
12
|
+
"ecma402",
|
|
13
|
+
"tc39"
|
|
14
|
+
],
|
|
15
|
+
"author": "Long Ho <holevietlong@gmail.com>",
|
|
16
|
+
"homepage": "https://github.com/formatjs/formatjs#readme",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"main": "index.umd.js",
|
|
19
|
+
"types": "index.d.ts",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/formatjs/formatjs.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/formatjs/formatjs/issues"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"tslib": "^2.4.0",
|
|
29
|
+
"@formatjs/intl-localematcher": "0.5.2",
|
|
30
|
+
"@formatjs/ecma402-abstract": "1.18.0"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _1 = require("./");
|
|
4
|
+
if (typeof Intl === 'undefined') {
|
|
5
|
+
if (typeof window !== 'undefined') {
|
|
6
|
+
Object.defineProperty(window, 'Intl', {
|
|
7
|
+
value: {},
|
|
8
|
+
});
|
|
9
|
+
// @ts-ignore we don't include @types/node so global isn't a thing
|
|
10
|
+
}
|
|
11
|
+
else if (typeof global !== 'undefined') {
|
|
12
|
+
// @ts-ignore we don't include @types/node so global isn't a thing
|
|
13
|
+
Object.defineProperty(global, 'Intl', {
|
|
14
|
+
value: {},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(Intl, 'DurationFormat', {
|
|
19
|
+
value: _1.DurationFormat,
|
|
20
|
+
});
|
package/polyfill.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/polyfill.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _1 = require("./");
|
|
4
|
+
var should_polyfill_1 = require("./should-polyfill");
|
|
5
|
+
if (typeof Intl === 'undefined') {
|
|
6
|
+
if (typeof window !== 'undefined') {
|
|
7
|
+
Object.defineProperty(window, 'Intl', {
|
|
8
|
+
value: {},
|
|
9
|
+
});
|
|
10
|
+
// @ts-ignore we don't include @types/node so global isn't a thing
|
|
11
|
+
}
|
|
12
|
+
else if (typeof global !== 'undefined') {
|
|
13
|
+
// @ts-ignore we don't include @types/node so global isn't a thing
|
|
14
|
+
Object.defineProperty(global, 'Intl', {
|
|
15
|
+
value: {},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if ((0, should_polyfill_1.shouldPolyfill)()) {
|
|
20
|
+
Object.defineProperty(Intl, 'DurationFormat', {
|
|
21
|
+
value: _1.DurationFormat,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function shouldPolyfill(): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DurationRecordSign = void 0;
|
|
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++) {
|
|
7
|
+
var key = TABLE_1_1[_i];
|
|
8
|
+
if (record[key] < 0) {
|
|
9
|
+
return -1;
|
|
10
|
+
}
|
|
11
|
+
if (record[key] > 0) {
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
exports.DurationRecordSign = DurationRecordSign;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function GetDurationUnitOptions<T extends object>(unit: keyof T, options: T, baseStyle: Exclude<T[keyof T], undefined>, stylesList: readonly T[keyof T][], digitalBase: Exclude<T[keyof T], undefined>, prevStyle: string): {
|
|
2
|
+
style: Exclude<T[keyof T], undefined>;
|
|
3
|
+
display: string | Exclude<T[keyof T], undefined>;
|
|
4
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetDurationUnitOptions = void 0;
|
|
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);
|
|
7
|
+
var displayDefault = 'always';
|
|
8
|
+
if (style === undefined) {
|
|
9
|
+
if (baseStyle === 'digital') {
|
|
10
|
+
if (unit !== 'hours' && unit !== 'minutes' && unit !== 'seconds') {
|
|
11
|
+
displayDefault = 'auto';
|
|
12
|
+
}
|
|
13
|
+
style = digitalBase;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
displayDefault = 'auto';
|
|
17
|
+
if (prevStyle === 'numeric' || prevStyle === '2-digit') {
|
|
18
|
+
style = 'numeric';
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
style = baseStyle;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
var displayField = "".concat(unit, "Display");
|
|
26
|
+
var display = (0, ecma402_abstract_1.GetOption)(options, displayField, 'string', ['always', 'auto'], displayDefault);
|
|
27
|
+
if (prevStyle === 'numeric' || prevStyle === '2-digit') {
|
|
28
|
+
if (style !== 'numeric' && style !== '2-digit') {
|
|
29
|
+
throw new RangeError("Can't mix numeric and non-numeric styles");
|
|
30
|
+
}
|
|
31
|
+
else if (unit === 'minutes' || unit === 'seconds') {
|
|
32
|
+
style = '2-digit';
|
|
33
|
+
}
|
|
34
|
+
if (style === 'numeric' &&
|
|
35
|
+
display === 'always' &&
|
|
36
|
+
(unit === 'milliseconds' ||
|
|
37
|
+
unit === 'microseconds' ||
|
|
38
|
+
unit === 'nanoseconds')) {
|
|
39
|
+
throw new RangeError("Can't display milliseconds, microseconds, or nanoseconds in numeric format");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
style: style,
|
|
44
|
+
display: display,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.GetDurationUnitOptions = GetDurationUnitOptions;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IsValidDurationRecord = void 0;
|
|
4
|
+
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
5
|
+
var constants_1 = require("../constants");
|
|
6
|
+
var DurationRecordSign_1 = require("./DurationRecordSign");
|
|
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++) {
|
|
10
|
+
var key = TABLE_1_1[_i];
|
|
11
|
+
var v = record[key];
|
|
12
|
+
(0, ecma402_abstract_1.invariant)(isFinite(Number(v)), "".concat(key, " is not finite"));
|
|
13
|
+
if (v < 0 && sign > 0) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (v > 0 && sign < 0) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
exports.IsValidDurationRecord = IsValidDurationRecord;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartitionDurationFormatPattern = void 0;
|
|
4
|
+
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
5
|
+
var constants_1 = require("../constants");
|
|
6
|
+
var core_1 = require("../core");
|
|
7
|
+
var get_internal_slots_1 = require("../get_internal_slots");
|
|
8
|
+
function PartitionDurationFormatPattern(df, duration) {
|
|
9
|
+
var result = [];
|
|
10
|
+
var done = false;
|
|
11
|
+
var separated = false;
|
|
12
|
+
var internalSlots = (0, get_internal_slots_1.getInternalSlots)(df);
|
|
13
|
+
var dataLocale = internalSlots.dataLocale;
|
|
14
|
+
var dataLocaleData = core_1.DurationFormat.localeData[dataLocale];
|
|
15
|
+
if (!dataLocaleData) {
|
|
16
|
+
throw new TypeError('Invalid locale');
|
|
17
|
+
}
|
|
18
|
+
var numberingSystem = internalSlots.numberingSystem;
|
|
19
|
+
var separator = dataLocaleData.digitalFormat[numberingSystem];
|
|
20
|
+
var _loop_1 = function (i) {
|
|
21
|
+
var row = constants_1.TABLE_2[i];
|
|
22
|
+
var value = duration[row.valueField];
|
|
23
|
+
var style = internalSlots[row.styleSlot];
|
|
24
|
+
var display = internalSlots[row.displaySlot];
|
|
25
|
+
var unit = row.unit, numberFormatUnit = row.numberFormatUnit;
|
|
26
|
+
var nfOpts = Object.create(null);
|
|
27
|
+
if (unit === 'seconds' ||
|
|
28
|
+
unit === 'milliseconds' ||
|
|
29
|
+
unit === 'microseconds') {
|
|
30
|
+
var nextStyle = void 0;
|
|
31
|
+
if (unit === 'seconds') {
|
|
32
|
+
nextStyle = internalSlots.milliseconds;
|
|
33
|
+
}
|
|
34
|
+
else if (unit === 'milliseconds') {
|
|
35
|
+
nextStyle = internalSlots.microseconds;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
nextStyle = internalSlots.nanoseconds;
|
|
39
|
+
}
|
|
40
|
+
if (nextStyle === 'numeric') {
|
|
41
|
+
if (unit === 'seconds') {
|
|
42
|
+
value +=
|
|
43
|
+
duration.milliseconds / 1e3 +
|
|
44
|
+
duration.microseconds / 1e6 +
|
|
45
|
+
duration.nanoseconds / 1e9;
|
|
46
|
+
}
|
|
47
|
+
else if (unit === 'milliseconds') {
|
|
48
|
+
value += duration.microseconds / 1e3 + duration.nanoseconds / 1e6;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
value += duration.nanoseconds / 1e3;
|
|
52
|
+
}
|
|
53
|
+
if (internalSlots.fractionalDigits === undefined) {
|
|
54
|
+
nfOpts.maximumFractionDigits = 9;
|
|
55
|
+
nfOpts.minimumFractionDigits = 0;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
nfOpts.maximumFractionDigits = internalSlots.fractionalDigits;
|
|
59
|
+
nfOpts.minimumFractionDigits = internalSlots.fractionalDigits;
|
|
60
|
+
}
|
|
61
|
+
nfOpts.roundingMode = 'trunc';
|
|
62
|
+
done = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (value !== 0 || display !== 'auto') {
|
|
66
|
+
nfOpts.numberingSystem = internalSlots.numberingSystem;
|
|
67
|
+
if (style === '2-digit') {
|
|
68
|
+
nfOpts.minimumIntegerDigits = 2;
|
|
69
|
+
}
|
|
70
|
+
if (style !== '2-digit' && style !== 'numeric') {
|
|
71
|
+
nfOpts.style = 'unit';
|
|
72
|
+
nfOpts.unit = numberFormatUnit;
|
|
73
|
+
nfOpts.unitDisplay = style;
|
|
74
|
+
}
|
|
75
|
+
var nf = new Intl.NumberFormat(internalSlots.locale, nfOpts);
|
|
76
|
+
var list_1;
|
|
77
|
+
if (!separated) {
|
|
78
|
+
list_1 = [];
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
list_1 = result[result.length - 1];
|
|
82
|
+
list_1.push({
|
|
83
|
+
type: 'literal',
|
|
84
|
+
value: separator,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
var parts = nf.formatToParts(value);
|
|
88
|
+
parts.forEach(function (_a) {
|
|
89
|
+
var type = _a.type, value = _a.value;
|
|
90
|
+
list_1.push({
|
|
91
|
+
type: type,
|
|
92
|
+
value: value,
|
|
93
|
+
unit: numberFormatUnit,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
if (!separated) {
|
|
97
|
+
if (style === '2-digit' || style === 'numeric') {
|
|
98
|
+
separated = true;
|
|
99
|
+
}
|
|
100
|
+
result.push(list_1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
separated = false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
for (var i = 0; i < constants_1.TABLE_2.length && !done; i++) {
|
|
108
|
+
_loop_1(i);
|
|
109
|
+
}
|
|
110
|
+
var lfOpts = Object.create(null);
|
|
111
|
+
lfOpts.type = 'unit';
|
|
112
|
+
var listStyle = internalSlots.style;
|
|
113
|
+
if (listStyle === 'digital') {
|
|
114
|
+
listStyle = 'short';
|
|
115
|
+
}
|
|
116
|
+
lfOpts.style = listStyle;
|
|
117
|
+
var lf = new Intl.ListFormat(internalSlots.locale, lfOpts);
|
|
118
|
+
var strings = [];
|
|
119
|
+
for (var _i = 0, result_1 = result; _i < result_1.length; _i++) {
|
|
120
|
+
var parts = result_1[_i];
|
|
121
|
+
var string = '';
|
|
122
|
+
for (var _a = 0, parts_1 = parts; _a < parts_1.length; _a++) {
|
|
123
|
+
var value = parts_1[_a].value;
|
|
124
|
+
string += value;
|
|
125
|
+
}
|
|
126
|
+
strings.push(string);
|
|
127
|
+
}
|
|
128
|
+
var formatted = lf.formatToParts(strings);
|
|
129
|
+
var resultIndex = 0;
|
|
130
|
+
var resultLength = result.length;
|
|
131
|
+
var flattened = [];
|
|
132
|
+
for (var _b = 0, formatted_1 = formatted; _b < formatted_1.length; _b++) {
|
|
133
|
+
var _c = formatted_1[_b], type = _c.type, value = _c.value;
|
|
134
|
+
if (type === 'element') {
|
|
135
|
+
(0, ecma402_abstract_1.invariant)(resultIndex < resultLength, 'Index out of bounds');
|
|
136
|
+
var parts = result[resultIndex];
|
|
137
|
+
for (var _d = 0, parts_2 = parts; _d < parts_2.length; _d++) {
|
|
138
|
+
var part = parts_2[_d];
|
|
139
|
+
flattened.push(part);
|
|
140
|
+
}
|
|
141
|
+
resultIndex++;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
(0, ecma402_abstract_1.invariant)(type === 'literal', 'Type must be literal');
|
|
145
|
+
flattened.push({
|
|
146
|
+
type: 'literal',
|
|
147
|
+
value: value,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return flattened;
|
|
152
|
+
}
|
|
153
|
+
exports.PartitionDurationFormatPattern = PartitionDurationFormatPattern;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToDurationRecord = void 0;
|
|
4
|
+
var IsValidDurationRecord_1 = require("./IsValidDurationRecord");
|
|
5
|
+
var ToIntegerIfIntegral_1 = require("./ToIntegerIfIntegral");
|
|
6
|
+
function ToDurationRecord(input) {
|
|
7
|
+
if (typeof input !== 'object') {
|
|
8
|
+
if (typeof input === 'string') {
|
|
9
|
+
throw new RangeError('Invalid duration format');
|
|
10
|
+
}
|
|
11
|
+
throw new TypeError('Invalid duration');
|
|
12
|
+
}
|
|
13
|
+
var result = {
|
|
14
|
+
years: 0,
|
|
15
|
+
months: 0,
|
|
16
|
+
weeks: 0,
|
|
17
|
+
days: 0,
|
|
18
|
+
hours: 0,
|
|
19
|
+
minutes: 0,
|
|
20
|
+
seconds: 0,
|
|
21
|
+
milliseconds: 0,
|
|
22
|
+
microseconds: 0,
|
|
23
|
+
nanoseconds: 0,
|
|
24
|
+
};
|
|
25
|
+
if (input.days !== undefined) {
|
|
26
|
+
result.days = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.days);
|
|
27
|
+
}
|
|
28
|
+
if (input.hours !== undefined) {
|
|
29
|
+
result.hours = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.hours);
|
|
30
|
+
}
|
|
31
|
+
if (input.microseconds !== undefined) {
|
|
32
|
+
result.microseconds = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.microseconds);
|
|
33
|
+
}
|
|
34
|
+
if (input.milliseconds !== undefined) {
|
|
35
|
+
result.milliseconds = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.milliseconds);
|
|
36
|
+
}
|
|
37
|
+
if (input.minutes !== undefined) {
|
|
38
|
+
result.minutes = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.minutes);
|
|
39
|
+
}
|
|
40
|
+
if (input.months !== undefined) {
|
|
41
|
+
result.months = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.months);
|
|
42
|
+
}
|
|
43
|
+
if (input.nanoseconds !== undefined) {
|
|
44
|
+
result.nanoseconds = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.nanoseconds);
|
|
45
|
+
}
|
|
46
|
+
if (input.seconds !== undefined) {
|
|
47
|
+
result.seconds = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.seconds);
|
|
48
|
+
}
|
|
49
|
+
if (input.weeks !== undefined) {
|
|
50
|
+
result.weeks = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.weeks);
|
|
51
|
+
}
|
|
52
|
+
if (input.years !== undefined) {
|
|
53
|
+
result.years = (0, ToIntegerIfIntegral_1.ToIntegerIfIntegral)(input.years);
|
|
54
|
+
}
|
|
55
|
+
if (input.years === undefined &&
|
|
56
|
+
input.months === undefined &&
|
|
57
|
+
input.weeks === undefined &&
|
|
58
|
+
input.days === undefined &&
|
|
59
|
+
input.hours === undefined &&
|
|
60
|
+
input.minutes === undefined &&
|
|
61
|
+
input.seconds === undefined &&
|
|
62
|
+
input.milliseconds === undefined &&
|
|
63
|
+
input.microseconds === undefined &&
|
|
64
|
+
input.nanoseconds === undefined) {
|
|
65
|
+
throw new TypeError('Invalid duration format');
|
|
66
|
+
}
|
|
67
|
+
if (!(0, IsValidDurationRecord_1.IsValidDurationRecord)(result)) {
|
|
68
|
+
throw new RangeError('Invalid duration format');
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
exports.ToDurationRecord = ToDurationRecord;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ToIntegerIfIntegral(arg: any): number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToIntegerIfIntegral = void 0;
|
|
4
|
+
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
5
|
+
function ToIntegerIfIntegral(arg) {
|
|
6
|
+
var number = (0, ecma402_abstract_1.ToNumber)(arg);
|
|
7
|
+
if (!Number.isInteger(number)) {
|
|
8
|
+
throw new RangeError("".concat(arg, " is not an integer"));
|
|
9
|
+
}
|
|
10
|
+
return number;
|
|
11
|
+
}
|
|
12
|
+
exports.ToIntegerIfIntegral = ToIntegerIfIntegral;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { DurationRecord } from './types';
|
|
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
|
+
}];
|