@formatjs/icu-skeleton-parser 1.3.10 → 1.3.11
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/BUILD +80 -0
- package/CHANGELOG.md +133 -0
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/date-time.ts +144 -0
- package/index.ts +2 -0
- package/number.ts +357 -0
- package/package.json +3 -3
- package/regex.generated.ts +2 -0
- package/scripts/global.ts +1 -0
- package/scripts/regex-gen.ts +19 -0
- package/tests/__snapshots__/index.test.ts.snap +389 -0
- package/tests/index.test.ts +65 -0
- package/tsconfig.json +5 -0
- package/date-time.d.ts +0 -8
- package/date-time.d.ts.map +0 -1
- package/date-time.js +0 -125
- package/index.d.ts +0 -3
- package/index.d.ts.map +0 -1
- package/index.js +0 -5
- package/lib/date-time.d.ts +0 -8
- package/lib/date-time.d.ts.map +0 -1
- package/lib/date-time.js +0 -121
- package/lib/index.d.ts +0 -3
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -2
- package/lib/number.d.ts +0 -14
- package/lib/number.d.ts.map +0 -1
- package/lib/number.js +0 -295
- package/lib/regex.generated.d.ts +0 -2
- package/lib/regex.generated.d.ts.map +0 -1
- package/lib/regex.generated.js +0 -2
- package/number.d.ts +0 -14
- package/number.d.ts.map +0 -1
- package/number.js +0 -300
- package/regex.generated.d.ts +0 -2
- package/regex.generated.d.ts.map +0 -1
- package/regex.generated.js +0 -5
package/lib/date-time.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
3
|
-
* Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
|
|
4
|
-
* with some tweaks
|
|
5
|
-
*/
|
|
6
|
-
var DATE_TIME_REGEX = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
|
|
7
|
-
/**
|
|
8
|
-
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
|
9
|
-
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
10
|
-
* @public
|
|
11
|
-
* @param skeleton skeleton string
|
|
12
|
-
*/
|
|
13
|
-
export function parseDateTimeSkeleton(skeleton) {
|
|
14
|
-
var result = {};
|
|
15
|
-
skeleton.replace(DATE_TIME_REGEX, function (match) {
|
|
16
|
-
var len = match.length;
|
|
17
|
-
switch (match[0]) {
|
|
18
|
-
// Era
|
|
19
|
-
case 'G':
|
|
20
|
-
result.era = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short';
|
|
21
|
-
break;
|
|
22
|
-
// Year
|
|
23
|
-
case 'y':
|
|
24
|
-
result.year = len === 2 ? '2-digit' : 'numeric';
|
|
25
|
-
break;
|
|
26
|
-
case 'Y':
|
|
27
|
-
case 'u':
|
|
28
|
-
case 'U':
|
|
29
|
-
case 'r':
|
|
30
|
-
throw new RangeError('`Y/u/U/r` (year) patterns are not supported, use `y` instead');
|
|
31
|
-
// Quarter
|
|
32
|
-
case 'q':
|
|
33
|
-
case 'Q':
|
|
34
|
-
throw new RangeError('`q/Q` (quarter) patterns are not supported');
|
|
35
|
-
// Month
|
|
36
|
-
case 'M':
|
|
37
|
-
case 'L':
|
|
38
|
-
result.month = ['numeric', '2-digit', 'short', 'long', 'narrow'][len - 1];
|
|
39
|
-
break;
|
|
40
|
-
// Week
|
|
41
|
-
case 'w':
|
|
42
|
-
case 'W':
|
|
43
|
-
throw new RangeError('`w/W` (week) patterns are not supported');
|
|
44
|
-
case 'd':
|
|
45
|
-
result.day = ['numeric', '2-digit'][len - 1];
|
|
46
|
-
break;
|
|
47
|
-
case 'D':
|
|
48
|
-
case 'F':
|
|
49
|
-
case 'g':
|
|
50
|
-
throw new RangeError('`D/F/g` (day) patterns are not supported, use `d` instead');
|
|
51
|
-
// Weekday
|
|
52
|
-
case 'E':
|
|
53
|
-
result.weekday = len === 4 ? 'short' : len === 5 ? 'narrow' : 'short';
|
|
54
|
-
break;
|
|
55
|
-
case 'e':
|
|
56
|
-
if (len < 4) {
|
|
57
|
-
throw new RangeError('`e..eee` (weekday) patterns are not supported');
|
|
58
|
-
}
|
|
59
|
-
result.weekday = ['short', 'long', 'narrow', 'short'][len - 4];
|
|
60
|
-
break;
|
|
61
|
-
case 'c':
|
|
62
|
-
if (len < 4) {
|
|
63
|
-
throw new RangeError('`c..ccc` (weekday) patterns are not supported');
|
|
64
|
-
}
|
|
65
|
-
result.weekday = ['short', 'long', 'narrow', 'short'][len - 4];
|
|
66
|
-
break;
|
|
67
|
-
// Period
|
|
68
|
-
case 'a': // AM, PM
|
|
69
|
-
result.hour12 = true;
|
|
70
|
-
break;
|
|
71
|
-
case 'b': // am, pm, noon, midnight
|
|
72
|
-
case 'B': // flexible day periods
|
|
73
|
-
throw new RangeError('`b/B` (period) patterns are not supported, use `a` instead');
|
|
74
|
-
// Hour
|
|
75
|
-
case 'h':
|
|
76
|
-
result.hourCycle = 'h12';
|
|
77
|
-
result.hour = ['numeric', '2-digit'][len - 1];
|
|
78
|
-
break;
|
|
79
|
-
case 'H':
|
|
80
|
-
result.hourCycle = 'h23';
|
|
81
|
-
result.hour = ['numeric', '2-digit'][len - 1];
|
|
82
|
-
break;
|
|
83
|
-
case 'K':
|
|
84
|
-
result.hourCycle = 'h11';
|
|
85
|
-
result.hour = ['numeric', '2-digit'][len - 1];
|
|
86
|
-
break;
|
|
87
|
-
case 'k':
|
|
88
|
-
result.hourCycle = 'h24';
|
|
89
|
-
result.hour = ['numeric', '2-digit'][len - 1];
|
|
90
|
-
break;
|
|
91
|
-
case 'j':
|
|
92
|
-
case 'J':
|
|
93
|
-
case 'C':
|
|
94
|
-
throw new RangeError('`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead');
|
|
95
|
-
// Minute
|
|
96
|
-
case 'm':
|
|
97
|
-
result.minute = ['numeric', '2-digit'][len - 1];
|
|
98
|
-
break;
|
|
99
|
-
// Second
|
|
100
|
-
case 's':
|
|
101
|
-
result.second = ['numeric', '2-digit'][len - 1];
|
|
102
|
-
break;
|
|
103
|
-
case 'S':
|
|
104
|
-
case 'A':
|
|
105
|
-
throw new RangeError('`S/A` (second) patterns are not supported, use `s` instead');
|
|
106
|
-
// Zone
|
|
107
|
-
case 'z': // 1..3, 4: specific non-location format
|
|
108
|
-
result.timeZoneName = len < 4 ? 'short' : 'long';
|
|
109
|
-
break;
|
|
110
|
-
case 'Z': // 1..3, 4, 5: The ISO8601 varios formats
|
|
111
|
-
case 'O': // 1, 4: miliseconds in day short, long
|
|
112
|
-
case 'v': // 1, 4: generic non-location format
|
|
113
|
-
case 'V': // 1, 2, 3, 4: time zone ID or city
|
|
114
|
-
case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
|
|
115
|
-
case 'x': // 1, 2, 3, 4: The ISO8601 varios formats
|
|
116
|
-
throw new RangeError('`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead');
|
|
117
|
-
}
|
|
118
|
-
return '';
|
|
119
|
-
});
|
|
120
|
-
return result;
|
|
121
|
-
}
|
package/lib/index.d.ts
DELETED
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/icu-skeleton-parser/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA"}
|
package/lib/index.js
DELETED
package/lib/number.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
|
|
2
|
-
export interface ExtendedNumberFormatOptions extends NumberFormatOptions {
|
|
3
|
-
scale?: number;
|
|
4
|
-
}
|
|
5
|
-
export interface NumberSkeletonToken {
|
|
6
|
-
stem: string;
|
|
7
|
-
options: string[];
|
|
8
|
-
}
|
|
9
|
-
export declare function parseNumberSkeletonFromString(skeleton: string): NumberSkeletonToken[];
|
|
10
|
-
/**
|
|
11
|
-
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
|
|
12
|
-
*/
|
|
13
|
-
export declare function parseNumberSkeleton(tokens: NumberSkeletonToken[]): ExtendedNumberFormatOptions;
|
|
14
|
-
//# sourceMappingURL=number.d.ts.map
|
package/lib/number.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../../../../packages/icu-skeleton-parser/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAG9D,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB;IACtE,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AACD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,GACf,mBAAmB,EAAE,CA0BvB;AAiID;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,mBAAmB,EAAE,GAC5B,2BAA2B,CAuL7B"}
|
package/lib/number.js
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
|
-
import { WHITE_SPACE_REGEX } from './regex.generated';
|
|
3
|
-
export function parseNumberSkeletonFromString(skeleton) {
|
|
4
|
-
if (skeleton.length === 0) {
|
|
5
|
-
throw new Error('Number skeleton cannot be empty');
|
|
6
|
-
}
|
|
7
|
-
// Parse the skeleton
|
|
8
|
-
var stringTokens = skeleton
|
|
9
|
-
.split(WHITE_SPACE_REGEX)
|
|
10
|
-
.filter(function (x) { return x.length > 0; });
|
|
11
|
-
var tokens = [];
|
|
12
|
-
for (var _i = 0, stringTokens_1 = stringTokens; _i < stringTokens_1.length; _i++) {
|
|
13
|
-
var stringToken = stringTokens_1[_i];
|
|
14
|
-
var stemAndOptions = stringToken.split('/');
|
|
15
|
-
if (stemAndOptions.length === 0) {
|
|
16
|
-
throw new Error('Invalid number skeleton');
|
|
17
|
-
}
|
|
18
|
-
var stem = stemAndOptions[0], options = stemAndOptions.slice(1);
|
|
19
|
-
for (var _a = 0, options_1 = options; _a < options_1.length; _a++) {
|
|
20
|
-
var option = options_1[_a];
|
|
21
|
-
if (option.length === 0) {
|
|
22
|
-
throw new Error('Invalid number skeleton');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
tokens.push({ stem: stem, options: options });
|
|
26
|
-
}
|
|
27
|
-
return tokens;
|
|
28
|
-
}
|
|
29
|
-
function icuUnitToEcma(unit) {
|
|
30
|
-
return unit.replace(/^(.*?)-/, '');
|
|
31
|
-
}
|
|
32
|
-
var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
|
|
33
|
-
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?[rs]?$/g;
|
|
34
|
-
var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
|
|
35
|
-
var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
|
|
36
|
-
function parseSignificantPrecision(str) {
|
|
37
|
-
var result = {};
|
|
38
|
-
if (str[str.length - 1] === 'r') {
|
|
39
|
-
result.roundingPriority = 'morePrecision';
|
|
40
|
-
}
|
|
41
|
-
else if (str[str.length - 1] === 's') {
|
|
42
|
-
result.roundingPriority = 'lessPrecision';
|
|
43
|
-
}
|
|
44
|
-
str.replace(SIGNIFICANT_PRECISION_REGEX, function (_, g1, g2) {
|
|
45
|
-
// @@@ case
|
|
46
|
-
if (typeof g2 !== 'string') {
|
|
47
|
-
result.minimumSignificantDigits = g1.length;
|
|
48
|
-
result.maximumSignificantDigits = g1.length;
|
|
49
|
-
}
|
|
50
|
-
// @@@+ case
|
|
51
|
-
else if (g2 === '+') {
|
|
52
|
-
result.minimumSignificantDigits = g1.length;
|
|
53
|
-
}
|
|
54
|
-
// .### case
|
|
55
|
-
else if (g1[0] === '#') {
|
|
56
|
-
result.maximumSignificantDigits = g1.length;
|
|
57
|
-
}
|
|
58
|
-
// .@@## or .@@@ case
|
|
59
|
-
else {
|
|
60
|
-
result.minimumSignificantDigits = g1.length;
|
|
61
|
-
result.maximumSignificantDigits =
|
|
62
|
-
g1.length + (typeof g2 === 'string' ? g2.length : 0);
|
|
63
|
-
}
|
|
64
|
-
return '';
|
|
65
|
-
});
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
function parseSign(str) {
|
|
69
|
-
switch (str) {
|
|
70
|
-
case 'sign-auto':
|
|
71
|
-
return {
|
|
72
|
-
signDisplay: 'auto',
|
|
73
|
-
};
|
|
74
|
-
case 'sign-accounting':
|
|
75
|
-
case '()':
|
|
76
|
-
return {
|
|
77
|
-
currencySign: 'accounting',
|
|
78
|
-
};
|
|
79
|
-
case 'sign-always':
|
|
80
|
-
case '+!':
|
|
81
|
-
return {
|
|
82
|
-
signDisplay: 'always',
|
|
83
|
-
};
|
|
84
|
-
case 'sign-accounting-always':
|
|
85
|
-
case '()!':
|
|
86
|
-
return {
|
|
87
|
-
signDisplay: 'always',
|
|
88
|
-
currencySign: 'accounting',
|
|
89
|
-
};
|
|
90
|
-
case 'sign-except-zero':
|
|
91
|
-
case '+?':
|
|
92
|
-
return {
|
|
93
|
-
signDisplay: 'exceptZero',
|
|
94
|
-
};
|
|
95
|
-
case 'sign-accounting-except-zero':
|
|
96
|
-
case '()?':
|
|
97
|
-
return {
|
|
98
|
-
signDisplay: 'exceptZero',
|
|
99
|
-
currencySign: 'accounting',
|
|
100
|
-
};
|
|
101
|
-
case 'sign-never':
|
|
102
|
-
case '+_':
|
|
103
|
-
return {
|
|
104
|
-
signDisplay: 'never',
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function parseConciseScientificAndEngineeringStem(stem) {
|
|
109
|
-
// Engineering
|
|
110
|
-
var result;
|
|
111
|
-
if (stem[0] === 'E' && stem[1] === 'E') {
|
|
112
|
-
result = {
|
|
113
|
-
notation: 'engineering',
|
|
114
|
-
};
|
|
115
|
-
stem = stem.slice(2);
|
|
116
|
-
}
|
|
117
|
-
else if (stem[0] === 'E') {
|
|
118
|
-
result = {
|
|
119
|
-
notation: 'scientific',
|
|
120
|
-
};
|
|
121
|
-
stem = stem.slice(1);
|
|
122
|
-
}
|
|
123
|
-
if (result) {
|
|
124
|
-
var signDisplay = stem.slice(0, 2);
|
|
125
|
-
if (signDisplay === '+!') {
|
|
126
|
-
result.signDisplay = 'always';
|
|
127
|
-
stem = stem.slice(2);
|
|
128
|
-
}
|
|
129
|
-
else if (signDisplay === '+?') {
|
|
130
|
-
result.signDisplay = 'exceptZero';
|
|
131
|
-
stem = stem.slice(2);
|
|
132
|
-
}
|
|
133
|
-
if (!CONCISE_INTEGER_WIDTH_REGEX.test(stem)) {
|
|
134
|
-
throw new Error('Malformed concise eng/scientific notation');
|
|
135
|
-
}
|
|
136
|
-
result.minimumIntegerDigits = stem.length;
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
function parseNotationOptions(opt) {
|
|
141
|
-
var result = {};
|
|
142
|
-
var signOpts = parseSign(opt);
|
|
143
|
-
if (signOpts) {
|
|
144
|
-
return signOpts;
|
|
145
|
-
}
|
|
146
|
-
return result;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
|
|
150
|
-
*/
|
|
151
|
-
export function parseNumberSkeleton(tokens) {
|
|
152
|
-
var result = {};
|
|
153
|
-
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
154
|
-
var token = tokens_1[_i];
|
|
155
|
-
switch (token.stem) {
|
|
156
|
-
case 'percent':
|
|
157
|
-
case '%':
|
|
158
|
-
result.style = 'percent';
|
|
159
|
-
continue;
|
|
160
|
-
case '%x100':
|
|
161
|
-
result.style = 'percent';
|
|
162
|
-
result.scale = 100;
|
|
163
|
-
continue;
|
|
164
|
-
case 'currency':
|
|
165
|
-
result.style = 'currency';
|
|
166
|
-
result.currency = token.options[0];
|
|
167
|
-
continue;
|
|
168
|
-
case 'group-off':
|
|
169
|
-
case ',_':
|
|
170
|
-
result.useGrouping = false;
|
|
171
|
-
continue;
|
|
172
|
-
case 'precision-integer':
|
|
173
|
-
case '.':
|
|
174
|
-
result.maximumFractionDigits = 0;
|
|
175
|
-
continue;
|
|
176
|
-
case 'measure-unit':
|
|
177
|
-
case 'unit':
|
|
178
|
-
result.style = 'unit';
|
|
179
|
-
result.unit = icuUnitToEcma(token.options[0]);
|
|
180
|
-
continue;
|
|
181
|
-
case 'compact-short':
|
|
182
|
-
case 'K':
|
|
183
|
-
result.notation = 'compact';
|
|
184
|
-
result.compactDisplay = 'short';
|
|
185
|
-
continue;
|
|
186
|
-
case 'compact-long':
|
|
187
|
-
case 'KK':
|
|
188
|
-
result.notation = 'compact';
|
|
189
|
-
result.compactDisplay = 'long';
|
|
190
|
-
continue;
|
|
191
|
-
case 'scientific':
|
|
192
|
-
result = __assign(__assign(__assign({}, result), { notation: 'scientific' }), token.options.reduce(function (all, opt) { return (__assign(__assign({}, all), parseNotationOptions(opt))); }, {}));
|
|
193
|
-
continue;
|
|
194
|
-
case 'engineering':
|
|
195
|
-
result = __assign(__assign(__assign({}, result), { notation: 'engineering' }), token.options.reduce(function (all, opt) { return (__assign(__assign({}, all), parseNotationOptions(opt))); }, {}));
|
|
196
|
-
continue;
|
|
197
|
-
case 'notation-simple':
|
|
198
|
-
result.notation = 'standard';
|
|
199
|
-
continue;
|
|
200
|
-
// https://github.com/unicode-org/icu/blob/master/icu4c/source/i18n/unicode/unumberformatter.h
|
|
201
|
-
case 'unit-width-narrow':
|
|
202
|
-
result.currencyDisplay = 'narrowSymbol';
|
|
203
|
-
result.unitDisplay = 'narrow';
|
|
204
|
-
continue;
|
|
205
|
-
case 'unit-width-short':
|
|
206
|
-
result.currencyDisplay = 'code';
|
|
207
|
-
result.unitDisplay = 'short';
|
|
208
|
-
continue;
|
|
209
|
-
case 'unit-width-full-name':
|
|
210
|
-
result.currencyDisplay = 'name';
|
|
211
|
-
result.unitDisplay = 'long';
|
|
212
|
-
continue;
|
|
213
|
-
case 'unit-width-iso-code':
|
|
214
|
-
result.currencyDisplay = 'symbol';
|
|
215
|
-
continue;
|
|
216
|
-
case 'scale':
|
|
217
|
-
result.scale = parseFloat(token.options[0]);
|
|
218
|
-
continue;
|
|
219
|
-
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width
|
|
220
|
-
case 'integer-width':
|
|
221
|
-
if (token.options.length > 1) {
|
|
222
|
-
throw new RangeError('integer-width stems only accept a single optional option');
|
|
223
|
-
}
|
|
224
|
-
token.options[0].replace(INTEGER_WIDTH_REGEX, function (_, g1, g2, g3, g4, g5) {
|
|
225
|
-
if (g1) {
|
|
226
|
-
result.minimumIntegerDigits = g2.length;
|
|
227
|
-
}
|
|
228
|
-
else if (g3 && g4) {
|
|
229
|
-
throw new Error('We currently do not support maximum integer digits');
|
|
230
|
-
}
|
|
231
|
-
else if (g5) {
|
|
232
|
-
throw new Error('We currently do not support exact integer digits');
|
|
233
|
-
}
|
|
234
|
-
return '';
|
|
235
|
-
});
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width
|
|
239
|
-
if (CONCISE_INTEGER_WIDTH_REGEX.test(token.stem)) {
|
|
240
|
-
result.minimumIntegerDigits = token.stem.length;
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
if (FRACTION_PRECISION_REGEX.test(token.stem)) {
|
|
244
|
-
// Precision
|
|
245
|
-
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#fraction-precision
|
|
246
|
-
// precision-integer case
|
|
247
|
-
if (token.options.length > 1) {
|
|
248
|
-
throw new RangeError('Fraction-precision stems only accept a single optional option');
|
|
249
|
-
}
|
|
250
|
-
token.stem.replace(FRACTION_PRECISION_REGEX, function (_, g1, g2, g3, g4, g5) {
|
|
251
|
-
// .000* case (before ICU67 it was .000+)
|
|
252
|
-
if (g2 === '*') {
|
|
253
|
-
result.minimumFractionDigits = g1.length;
|
|
254
|
-
}
|
|
255
|
-
// .### case
|
|
256
|
-
else if (g3 && g3[0] === '#') {
|
|
257
|
-
result.maximumFractionDigits = g3.length;
|
|
258
|
-
}
|
|
259
|
-
// .00## case
|
|
260
|
-
else if (g4 && g5) {
|
|
261
|
-
result.minimumFractionDigits = g4.length;
|
|
262
|
-
result.maximumFractionDigits = g4.length + g5.length;
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
result.minimumFractionDigits = g1.length;
|
|
266
|
-
result.maximumFractionDigits = g1.length;
|
|
267
|
-
}
|
|
268
|
-
return '';
|
|
269
|
-
});
|
|
270
|
-
var opt = token.options[0];
|
|
271
|
-
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#trailing-zero-display
|
|
272
|
-
if (opt === 'w') {
|
|
273
|
-
result = __assign(__assign({}, result), { trailingZeroDisplay: 'stripIfInteger' });
|
|
274
|
-
}
|
|
275
|
-
else if (opt) {
|
|
276
|
-
result = __assign(__assign({}, result), parseSignificantPrecision(opt));
|
|
277
|
-
}
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#significant-digits-precision
|
|
281
|
-
if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) {
|
|
282
|
-
result = __assign(__assign({}, result), parseSignificantPrecision(token.stem));
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
var signOpts = parseSign(token.stem);
|
|
286
|
-
if (signOpts) {
|
|
287
|
-
result = __assign(__assign({}, result), signOpts);
|
|
288
|
-
}
|
|
289
|
-
var conciseScientificAndEngineeringOpts = parseConciseScientificAndEngineeringStem(token.stem);
|
|
290
|
-
if (conciseScientificAndEngineeringOpts) {
|
|
291
|
-
result = __assign(__assign({}, result), conciseScientificAndEngineeringOpts);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
return result;
|
|
295
|
-
}
|
package/lib/regex.generated.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regex.generated.d.ts","sourceRoot":"","sources":["../../../../../../packages/icu-skeleton-parser/regex.generated.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,iBAAiB,QAA0C,CAAA"}
|
package/lib/regex.generated.js
DELETED
package/number.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
|
|
2
|
-
export interface ExtendedNumberFormatOptions extends NumberFormatOptions {
|
|
3
|
-
scale?: number;
|
|
4
|
-
}
|
|
5
|
-
export interface NumberSkeletonToken {
|
|
6
|
-
stem: string;
|
|
7
|
-
options: string[];
|
|
8
|
-
}
|
|
9
|
-
export declare function parseNumberSkeletonFromString(skeleton: string): NumberSkeletonToken[];
|
|
10
|
-
/**
|
|
11
|
-
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
|
|
12
|
-
*/
|
|
13
|
-
export declare function parseNumberSkeleton(tokens: NumberSkeletonToken[]): ExtendedNumberFormatOptions;
|
|
14
|
-
//# sourceMappingURL=number.d.ts.map
|
package/number.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../../../packages/icu-skeleton-parser/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAG9D,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB;IACtE,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AACD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,GACf,mBAAmB,EAAE,CA0BvB;AAiID;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,mBAAmB,EAAE,GAC5B,2BAA2B,CAuL7B"}
|