@common.js/formatjs__icu-skeleton-parser 2.1.10
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 +5 -0
- package/index.d.ts +68 -0
- package/index.js +558 -0
- package/index.js.map +1 -0
- package/package.json +13 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 FormatJS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# @common.js/formatjs__icu-skeleton-parser
|
|
2
|
+
|
|
3
|
+
The [@formatjs/icu-skeleton-parser](https://www.npmjs.com/package/@formatjs/icu-skeleton-parser) package exported as CommonJS modules.
|
|
4
|
+
|
|
5
|
+
Exported from [@formatjs/icu-skeleton-parser@2.1.10](https://www.npmjs.com/package/@formatjs/icu-skeleton-parser/v/2.1.10) using https://github.com/etienne-martin/common.js.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region packages/icu-skeleton-parser/date-time.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
|
4
|
+
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
5
|
+
* @public
|
|
6
|
+
* @param skeleton skeleton string
|
|
7
|
+
*/
|
|
8
|
+
declare function parseDateTimeSkeleton(skeleton: string): Intl.DateTimeFormatOptions;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region packages/ecma402-abstract/types/number.d.ts
|
|
11
|
+
type NumberFormatNotation = "standard" | "scientific" | "engineering" | "compact";
|
|
12
|
+
type RoundingPriorityType = "auto" | "morePrecision" | "lessPrecision";
|
|
13
|
+
type RoundingModeType = "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven";
|
|
14
|
+
type UseGroupingType = "min2" | "auto" | "always" | boolean;
|
|
15
|
+
interface NumberFormatDigitOptions {
|
|
16
|
+
minimumIntegerDigits?: number;
|
|
17
|
+
minimumSignificantDigits?: number;
|
|
18
|
+
maximumSignificantDigits?: number;
|
|
19
|
+
minimumFractionDigits?: number;
|
|
20
|
+
maximumFractionDigits?: number;
|
|
21
|
+
roundingPriority?: RoundingPriorityType;
|
|
22
|
+
roundingIncrement?: number;
|
|
23
|
+
roundingMode?: RoundingModeType;
|
|
24
|
+
trailingZeroDisplay?: TrailingZeroDisplay;
|
|
25
|
+
}
|
|
26
|
+
type NumberFormatOptionsLocaleMatcher = "lookup" | "best fit";
|
|
27
|
+
type NumberFormatOptionsStyle = "decimal" | "percent" | "currency" | "unit";
|
|
28
|
+
type NumberFormatOptionsCompactDisplay = "short" | "long";
|
|
29
|
+
type NumberFormatOptionsCurrencyDisplay = "symbol" | "code" | "name" | "narrowSymbol";
|
|
30
|
+
type NumberFormatOptionsCurrencySign = "standard" | "accounting";
|
|
31
|
+
type NumberFormatOptionsNotation = NumberFormatNotation;
|
|
32
|
+
type NumberFormatOptionsSignDisplay = "auto" | "always" | "never" | "exceptZero" | "negative";
|
|
33
|
+
type NumberFormatOptionsUnitDisplay = "long" | "short" | "narrow";
|
|
34
|
+
type TrailingZeroDisplay = "auto" | "stripIfInteger";
|
|
35
|
+
type NumberFormatOptions = Omit<Intl.NumberFormatOptions, "signDisplay" | "useGrouping"> & NumberFormatDigitOptions & {
|
|
36
|
+
localeMatcher?: NumberFormatOptionsLocaleMatcher;
|
|
37
|
+
style?: NumberFormatOptionsStyle;
|
|
38
|
+
compactDisplay?: NumberFormatOptionsCompactDisplay;
|
|
39
|
+
currencyDisplay?: NumberFormatOptionsCurrencyDisplay;
|
|
40
|
+
currencySign?: NumberFormatOptionsCurrencySign;
|
|
41
|
+
notation?: NumberFormatOptionsNotation;
|
|
42
|
+
signDisplay?: NumberFormatOptionsSignDisplay;
|
|
43
|
+
unit?: string;
|
|
44
|
+
unitDisplay?: NumberFormatOptionsUnitDisplay;
|
|
45
|
+
numberingSystem?: string;
|
|
46
|
+
trailingZeroDisplay?: TrailingZeroDisplay;
|
|
47
|
+
roundingPriority?: RoundingPriorityType;
|
|
48
|
+
roundingIncrement?: number;
|
|
49
|
+
roundingMode?: RoundingModeType;
|
|
50
|
+
useGrouping?: UseGroupingType;
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region packages/icu-skeleton-parser/number.d.ts
|
|
54
|
+
interface ExtendedNumberFormatOptions extends NumberFormatOptions {
|
|
55
|
+
scale?: number;
|
|
56
|
+
}
|
|
57
|
+
interface NumberSkeletonToken {
|
|
58
|
+
stem: string;
|
|
59
|
+
options: string[];
|
|
60
|
+
}
|
|
61
|
+
declare function parseNumberSkeletonFromString(skeleton: string): NumberSkeletonToken[];
|
|
62
|
+
/**
|
|
63
|
+
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
|
|
64
|
+
*/
|
|
65
|
+
declare function parseNumberSkeleton(tokens: NumberSkeletonToken[]): ExtendedNumberFormatOptions;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { ExtendedNumberFormatOptions, NumberSkeletonToken, parseDateTimeSkeleton, parseNumberSkeleton, parseNumberSkeletonFromString };
|
|
68
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.js
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
//#region packages/icu-skeleton-parser/date-time.ts
|
|
2
|
+
/**
|
|
3
|
+
* https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
4
|
+
* Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
|
|
5
|
+
* with some tweaks
|
|
6
|
+
*/ "use strict";
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
function _export(target, all) {
|
|
11
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: all[name]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_export(exports, {
|
|
17
|
+
parseDateTimeSkeleton: function() {
|
|
18
|
+
return parseDateTimeSkeleton;
|
|
19
|
+
},
|
|
20
|
+
parseNumberSkeleton: function() {
|
|
21
|
+
return parseNumberSkeleton;
|
|
22
|
+
},
|
|
23
|
+
parseNumberSkeletonFromString: function() {
|
|
24
|
+
return parseNumberSkeletonFromString;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
function _arrayLikeToArray(arr, len) {
|
|
28
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
29
|
+
for(var i1 = 0, arr2 = new Array(len); i1 < len; i1++)arr2[i1] = arr[i1];
|
|
30
|
+
return arr2;
|
|
31
|
+
}
|
|
32
|
+
function _arrayWithHoles(arr) {
|
|
33
|
+
if (Array.isArray(arr)) return arr;
|
|
34
|
+
}
|
|
35
|
+
function _defineProperty(obj, key, value) {
|
|
36
|
+
if (key in obj) {
|
|
37
|
+
Object.defineProperty(obj, key, {
|
|
38
|
+
value: value,
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
obj[key] = value;
|
|
45
|
+
}
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
function _iterableToArray(iter) {
|
|
49
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
50
|
+
}
|
|
51
|
+
function _nonIterableRest() {
|
|
52
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
53
|
+
}
|
|
54
|
+
function _objectSpread(target) {
|
|
55
|
+
for(var i1 = 1; i1 < arguments.length; i1++){
|
|
56
|
+
var source = arguments[i1] != null ? arguments[i1] : {};
|
|
57
|
+
var ownKeys = Object.keys(source);
|
|
58
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
59
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
60
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
ownKeys.forEach(function(key) {
|
|
64
|
+
_defineProperty(target, key, source[key]);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return target;
|
|
68
|
+
}
|
|
69
|
+
function ownKeys(object, enumerableOnly) {
|
|
70
|
+
var keys = Object.keys(object);
|
|
71
|
+
if (Object.getOwnPropertySymbols) {
|
|
72
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
73
|
+
if (enumerableOnly) {
|
|
74
|
+
symbols = symbols.filter(function(sym) {
|
|
75
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
keys.push.apply(keys, symbols);
|
|
79
|
+
}
|
|
80
|
+
return keys;
|
|
81
|
+
}
|
|
82
|
+
function _objectSpreadProps(target, source) {
|
|
83
|
+
source = source != null ? source : {};
|
|
84
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
85
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
86
|
+
} else {
|
|
87
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
88
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
function _toArray(arr) {
|
|
94
|
+
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
95
|
+
}
|
|
96
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
97
|
+
if (!o) return;
|
|
98
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
99
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
100
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
101
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
102
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
103
|
+
}
|
|
104
|
+
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;
|
|
105
|
+
/**
|
|
106
|
+
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
|
107
|
+
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
108
|
+
* @public
|
|
109
|
+
* @param skeleton skeleton string
|
|
110
|
+
*/ function parseDateTimeSkeleton(skeleton) {
|
|
111
|
+
var result = {};
|
|
112
|
+
skeleton.replace(DATE_TIME_REGEX, function(match) {
|
|
113
|
+
var len = match.length;
|
|
114
|
+
switch(match[0]){
|
|
115
|
+
case "G":
|
|
116
|
+
result.era = len === 4 ? "long" : len === 5 ? "narrow" : "short";
|
|
117
|
+
break;
|
|
118
|
+
case "y":
|
|
119
|
+
result.year = len === 2 ? "2-digit" : "numeric";
|
|
120
|
+
break;
|
|
121
|
+
case "Y":
|
|
122
|
+
case "u":
|
|
123
|
+
case "U":
|
|
124
|
+
case "r":
|
|
125
|
+
throw new RangeError("`Y/u/U/r` (year) patterns are not supported, use `y` instead");
|
|
126
|
+
case "q":
|
|
127
|
+
case "Q":
|
|
128
|
+
throw new RangeError("`q/Q` (quarter) patterns are not supported");
|
|
129
|
+
case "M":
|
|
130
|
+
case "L":
|
|
131
|
+
result.month = [
|
|
132
|
+
"numeric",
|
|
133
|
+
"2-digit",
|
|
134
|
+
"short",
|
|
135
|
+
"long",
|
|
136
|
+
"narrow"
|
|
137
|
+
][len - 1];
|
|
138
|
+
break;
|
|
139
|
+
case "w":
|
|
140
|
+
case "W":
|
|
141
|
+
throw new RangeError("`w/W` (week) patterns are not supported");
|
|
142
|
+
case "d":
|
|
143
|
+
result.day = [
|
|
144
|
+
"numeric",
|
|
145
|
+
"2-digit"
|
|
146
|
+
][len - 1];
|
|
147
|
+
break;
|
|
148
|
+
case "D":
|
|
149
|
+
case "F":
|
|
150
|
+
case "g":
|
|
151
|
+
throw new RangeError("`D/F/g` (day) patterns are not supported, use `d` instead");
|
|
152
|
+
case "E":
|
|
153
|
+
result.weekday = len === 4 ? "long" : len === 5 ? "narrow" : "short";
|
|
154
|
+
break;
|
|
155
|
+
case "e":
|
|
156
|
+
if (len < 4) throw new RangeError("`e..eee` (weekday) patterns are not supported");
|
|
157
|
+
result.weekday = [
|
|
158
|
+
"short",
|
|
159
|
+
"long",
|
|
160
|
+
"narrow",
|
|
161
|
+
"short"
|
|
162
|
+
][len - 4];
|
|
163
|
+
break;
|
|
164
|
+
case "c":
|
|
165
|
+
if (len < 4) throw new RangeError("`c..ccc` (weekday) patterns are not supported");
|
|
166
|
+
result.weekday = [
|
|
167
|
+
"short",
|
|
168
|
+
"long",
|
|
169
|
+
"narrow",
|
|
170
|
+
"short"
|
|
171
|
+
][len - 4];
|
|
172
|
+
break;
|
|
173
|
+
case "a":
|
|
174
|
+
result.hour12 = true;
|
|
175
|
+
break;
|
|
176
|
+
case "b":
|
|
177
|
+
case "B":
|
|
178
|
+
throw new RangeError("`b/B` (period) patterns are not supported, use `a` instead");
|
|
179
|
+
case "h":
|
|
180
|
+
result.hourCycle = "h12";
|
|
181
|
+
result.hour = [
|
|
182
|
+
"numeric",
|
|
183
|
+
"2-digit"
|
|
184
|
+
][len - 1];
|
|
185
|
+
break;
|
|
186
|
+
case "H":
|
|
187
|
+
result.hourCycle = "h23";
|
|
188
|
+
result.hour = [
|
|
189
|
+
"numeric",
|
|
190
|
+
"2-digit"
|
|
191
|
+
][len - 1];
|
|
192
|
+
break;
|
|
193
|
+
case "K":
|
|
194
|
+
result.hourCycle = "h11";
|
|
195
|
+
result.hour = [
|
|
196
|
+
"numeric",
|
|
197
|
+
"2-digit"
|
|
198
|
+
][len - 1];
|
|
199
|
+
break;
|
|
200
|
+
case "k":
|
|
201
|
+
result.hourCycle = "h24";
|
|
202
|
+
result.hour = [
|
|
203
|
+
"numeric",
|
|
204
|
+
"2-digit"
|
|
205
|
+
][len - 1];
|
|
206
|
+
break;
|
|
207
|
+
case "j":
|
|
208
|
+
case "J":
|
|
209
|
+
case "C":
|
|
210
|
+
throw new RangeError("`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead");
|
|
211
|
+
case "m":
|
|
212
|
+
result.minute = [
|
|
213
|
+
"numeric",
|
|
214
|
+
"2-digit"
|
|
215
|
+
][len - 1];
|
|
216
|
+
break;
|
|
217
|
+
case "s":
|
|
218
|
+
result.second = [
|
|
219
|
+
"numeric",
|
|
220
|
+
"2-digit"
|
|
221
|
+
][len - 1];
|
|
222
|
+
break;
|
|
223
|
+
case "S":
|
|
224
|
+
case "A":
|
|
225
|
+
throw new RangeError("`S/A` (second) patterns are not supported, use `s` instead");
|
|
226
|
+
case "z":
|
|
227
|
+
result.timeZoneName = len < 4 ? "short" : "long";
|
|
228
|
+
break;
|
|
229
|
+
case "Z":
|
|
230
|
+
case "O":
|
|
231
|
+
case "v":
|
|
232
|
+
case "V":
|
|
233
|
+
case "X":
|
|
234
|
+
case "x":
|
|
235
|
+
throw new RangeError("`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead");
|
|
236
|
+
}
|
|
237
|
+
return "";
|
|
238
|
+
});
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region node_modules/.aspect_rules_js/@formatjs_generated+unicode@0.0.0/node_modules/@formatjs_generated/unicode/icu-skeleton-parser-regex.js
|
|
243
|
+
var WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/i;
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region packages/icu-skeleton-parser/number.ts
|
|
246
|
+
function parseNumberSkeletonFromString(skeleton) {
|
|
247
|
+
if (skeleton.length === 0) throw new Error("Number skeleton cannot be empty");
|
|
248
|
+
var stringTokens = skeleton.split(WHITE_SPACE_REGEX).filter(function(x) {
|
|
249
|
+
return x.length > 0;
|
|
250
|
+
});
|
|
251
|
+
var tokens = [];
|
|
252
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
253
|
+
try {
|
|
254
|
+
for(var _iterator = stringTokens[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
255
|
+
var stringToken = _step.value;
|
|
256
|
+
var stemAndOptions = stringToken.split("/");
|
|
257
|
+
if (stemAndOptions.length === 0) throw new Error("Invalid number skeleton");
|
|
258
|
+
var _stemAndOptions = _toArray(stemAndOptions), stem = _stemAndOptions[0], options = _stemAndOptions.slice(1);
|
|
259
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
260
|
+
try {
|
|
261
|
+
for(var _iterator1 = options[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
262
|
+
var option = _step1.value;
|
|
263
|
+
if (option.length === 0) throw new Error("Invalid number skeleton");
|
|
264
|
+
}
|
|
265
|
+
} catch (err) {
|
|
266
|
+
_didIteratorError1 = true;
|
|
267
|
+
_iteratorError1 = err;
|
|
268
|
+
} finally{
|
|
269
|
+
try {
|
|
270
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
271
|
+
_iterator1.return();
|
|
272
|
+
}
|
|
273
|
+
} finally{
|
|
274
|
+
if (_didIteratorError1) {
|
|
275
|
+
throw _iteratorError1;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
tokens.push({
|
|
280
|
+
stem: stem,
|
|
281
|
+
options: options
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
} catch (err) {
|
|
285
|
+
_didIteratorError = true;
|
|
286
|
+
_iteratorError = err;
|
|
287
|
+
} finally{
|
|
288
|
+
try {
|
|
289
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
290
|
+
_iterator.return();
|
|
291
|
+
}
|
|
292
|
+
} finally{
|
|
293
|
+
if (_didIteratorError) {
|
|
294
|
+
throw _iteratorError;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return tokens;
|
|
299
|
+
}
|
|
300
|
+
function icuUnitToEcma(unit) {
|
|
301
|
+
return unit.replace(/^(.*?)-/, "");
|
|
302
|
+
}
|
|
303
|
+
var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
|
|
304
|
+
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?[rs]?$/g;
|
|
305
|
+
var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
|
|
306
|
+
var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
|
|
307
|
+
function parseSignificantPrecision(str) {
|
|
308
|
+
var result = {};
|
|
309
|
+
if (str[str.length - 1] === "r") result.roundingPriority = "morePrecision";
|
|
310
|
+
else if (str[str.length - 1] === "s") result.roundingPriority = "lessPrecision";
|
|
311
|
+
str.replace(SIGNIFICANT_PRECISION_REGEX, function(_, g1, g2) {
|
|
312
|
+
if (typeof g2 !== "string") {
|
|
313
|
+
result.minimumSignificantDigits = g1.length;
|
|
314
|
+
result.maximumSignificantDigits = g1.length;
|
|
315
|
+
} else if (g2 === "+") result.minimumSignificantDigits = g1.length;
|
|
316
|
+
else if (g1[0] === "#") result.maximumSignificantDigits = g1.length;
|
|
317
|
+
else {
|
|
318
|
+
result.minimumSignificantDigits = g1.length;
|
|
319
|
+
result.maximumSignificantDigits = g1.length + (typeof g2 === "string" ? g2.length : 0);
|
|
320
|
+
}
|
|
321
|
+
return "";
|
|
322
|
+
});
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
function parseSign(str) {
|
|
326
|
+
switch(str){
|
|
327
|
+
case "sign-auto":
|
|
328
|
+
return {
|
|
329
|
+
signDisplay: "auto"
|
|
330
|
+
};
|
|
331
|
+
case "sign-accounting":
|
|
332
|
+
case "()":
|
|
333
|
+
return {
|
|
334
|
+
currencySign: "accounting"
|
|
335
|
+
};
|
|
336
|
+
case "sign-always":
|
|
337
|
+
case "+!":
|
|
338
|
+
return {
|
|
339
|
+
signDisplay: "always"
|
|
340
|
+
};
|
|
341
|
+
case "sign-accounting-always":
|
|
342
|
+
case "()!":
|
|
343
|
+
return {
|
|
344
|
+
signDisplay: "always",
|
|
345
|
+
currencySign: "accounting"
|
|
346
|
+
};
|
|
347
|
+
case "sign-except-zero":
|
|
348
|
+
case "+?":
|
|
349
|
+
return {
|
|
350
|
+
signDisplay: "exceptZero"
|
|
351
|
+
};
|
|
352
|
+
case "sign-accounting-except-zero":
|
|
353
|
+
case "()?":
|
|
354
|
+
return {
|
|
355
|
+
signDisplay: "exceptZero",
|
|
356
|
+
currencySign: "accounting"
|
|
357
|
+
};
|
|
358
|
+
case "sign-never":
|
|
359
|
+
case "+_":
|
|
360
|
+
return {
|
|
361
|
+
signDisplay: "never"
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function parseConciseScientificAndEngineeringStem(stem) {
|
|
366
|
+
var result;
|
|
367
|
+
if (stem[0] === "E" && stem[1] === "E") {
|
|
368
|
+
result = {
|
|
369
|
+
notation: "engineering"
|
|
370
|
+
};
|
|
371
|
+
stem = stem.slice(2);
|
|
372
|
+
} else if (stem[0] === "E") {
|
|
373
|
+
result = {
|
|
374
|
+
notation: "scientific"
|
|
375
|
+
};
|
|
376
|
+
stem = stem.slice(1);
|
|
377
|
+
}
|
|
378
|
+
if (result) {
|
|
379
|
+
var signDisplay = stem.slice(0, 2);
|
|
380
|
+
if (signDisplay === "+!") {
|
|
381
|
+
result.signDisplay = "always";
|
|
382
|
+
stem = stem.slice(2);
|
|
383
|
+
} else if (signDisplay === "+?") {
|
|
384
|
+
result.signDisplay = "exceptZero";
|
|
385
|
+
stem = stem.slice(2);
|
|
386
|
+
}
|
|
387
|
+
if (!CONCISE_INTEGER_WIDTH_REGEX.test(stem)) throw new Error("Malformed concise eng/scientific notation");
|
|
388
|
+
result.minimumIntegerDigits = stem.length;
|
|
389
|
+
}
|
|
390
|
+
return result;
|
|
391
|
+
}
|
|
392
|
+
function parseNotationOptions(opt) {
|
|
393
|
+
var result = {};
|
|
394
|
+
var signOpts = parseSign(opt);
|
|
395
|
+
if (signOpts) return signOpts;
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
|
|
400
|
+
*/ function parseNumberSkeleton(tokens) {
|
|
401
|
+
var result = {};
|
|
402
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
403
|
+
try {
|
|
404
|
+
for(var _iterator = tokens[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
405
|
+
var token = _step.value;
|
|
406
|
+
switch(token.stem){
|
|
407
|
+
case "percent":
|
|
408
|
+
case "%":
|
|
409
|
+
result.style = "percent";
|
|
410
|
+
continue;
|
|
411
|
+
case "%x100":
|
|
412
|
+
result.style = "percent";
|
|
413
|
+
result.scale = 100;
|
|
414
|
+
continue;
|
|
415
|
+
case "currency":
|
|
416
|
+
result.style = "currency";
|
|
417
|
+
result.currency = token.options[0];
|
|
418
|
+
continue;
|
|
419
|
+
case "group-off":
|
|
420
|
+
case ",_":
|
|
421
|
+
result.useGrouping = false;
|
|
422
|
+
continue;
|
|
423
|
+
case "precision-integer":
|
|
424
|
+
case ".":
|
|
425
|
+
result.maximumFractionDigits = 0;
|
|
426
|
+
continue;
|
|
427
|
+
case "measure-unit":
|
|
428
|
+
case "unit":
|
|
429
|
+
result.style = "unit";
|
|
430
|
+
result.unit = icuUnitToEcma(token.options[0]);
|
|
431
|
+
continue;
|
|
432
|
+
case "compact-short":
|
|
433
|
+
case "K":
|
|
434
|
+
result.notation = "compact";
|
|
435
|
+
result.compactDisplay = "short";
|
|
436
|
+
continue;
|
|
437
|
+
case "compact-long":
|
|
438
|
+
case "KK":
|
|
439
|
+
result.notation = "compact";
|
|
440
|
+
result.compactDisplay = "long";
|
|
441
|
+
continue;
|
|
442
|
+
case "scientific":
|
|
443
|
+
result = _objectSpread(_objectSpreadProps(_objectSpread({}, result), {
|
|
444
|
+
notation: "scientific"
|
|
445
|
+
}), token.options.reduce(function(all, opt) {
|
|
446
|
+
return _objectSpread({}, all, parseNotationOptions(opt));
|
|
447
|
+
}, {}));
|
|
448
|
+
continue;
|
|
449
|
+
case "engineering":
|
|
450
|
+
result = _objectSpread(_objectSpreadProps(_objectSpread({}, result), {
|
|
451
|
+
notation: "engineering"
|
|
452
|
+
}), token.options.reduce(function(all, opt) {
|
|
453
|
+
return _objectSpread({}, all, parseNotationOptions(opt));
|
|
454
|
+
}, {}));
|
|
455
|
+
continue;
|
|
456
|
+
case "notation-simple":
|
|
457
|
+
result.notation = "standard";
|
|
458
|
+
continue;
|
|
459
|
+
case "unit-width-narrow":
|
|
460
|
+
result.currencyDisplay = "narrowSymbol";
|
|
461
|
+
result.unitDisplay = "narrow";
|
|
462
|
+
continue;
|
|
463
|
+
case "unit-width-short":
|
|
464
|
+
result.currencyDisplay = "code";
|
|
465
|
+
result.unitDisplay = "short";
|
|
466
|
+
continue;
|
|
467
|
+
case "unit-width-full-name":
|
|
468
|
+
result.currencyDisplay = "name";
|
|
469
|
+
result.unitDisplay = "long";
|
|
470
|
+
continue;
|
|
471
|
+
case "unit-width-iso-code":
|
|
472
|
+
result.currencyDisplay = "symbol";
|
|
473
|
+
continue;
|
|
474
|
+
case "scale":
|
|
475
|
+
result.scale = parseFloat(token.options[0]);
|
|
476
|
+
continue;
|
|
477
|
+
case "rounding-mode-floor":
|
|
478
|
+
result.roundingMode = "floor";
|
|
479
|
+
continue;
|
|
480
|
+
case "rounding-mode-ceiling":
|
|
481
|
+
result.roundingMode = "ceil";
|
|
482
|
+
continue;
|
|
483
|
+
case "rounding-mode-down":
|
|
484
|
+
result.roundingMode = "trunc";
|
|
485
|
+
continue;
|
|
486
|
+
case "rounding-mode-up":
|
|
487
|
+
result.roundingMode = "expand";
|
|
488
|
+
continue;
|
|
489
|
+
case "rounding-mode-half-even":
|
|
490
|
+
result.roundingMode = "halfEven";
|
|
491
|
+
continue;
|
|
492
|
+
case "rounding-mode-half-down":
|
|
493
|
+
result.roundingMode = "halfTrunc";
|
|
494
|
+
continue;
|
|
495
|
+
case "rounding-mode-half-up":
|
|
496
|
+
result.roundingMode = "halfExpand";
|
|
497
|
+
continue;
|
|
498
|
+
case "integer-width":
|
|
499
|
+
if (token.options.length > 1) throw new RangeError("integer-width stems only accept a single optional option");
|
|
500
|
+
token.options[0].replace(INTEGER_WIDTH_REGEX, function(_, g1, g2, g3, g4, g5) {
|
|
501
|
+
if (g1) result.minimumIntegerDigits = g2.length;
|
|
502
|
+
else if (g3 && g4) throw new Error("We currently do not support maximum integer digits");
|
|
503
|
+
else if (g5) throw new Error("We currently do not support exact integer digits");
|
|
504
|
+
return "";
|
|
505
|
+
});
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (CONCISE_INTEGER_WIDTH_REGEX.test(token.stem)) {
|
|
509
|
+
result.minimumIntegerDigits = token.stem.length;
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
if (FRACTION_PRECISION_REGEX.test(token.stem)) {
|
|
513
|
+
if (token.options.length > 1) throw new RangeError("Fraction-precision stems only accept a single optional option");
|
|
514
|
+
token.stem.replace(FRACTION_PRECISION_REGEX, function(_, g1, g2, g3, g4, g5) {
|
|
515
|
+
if (g2 === "*") result.minimumFractionDigits = g1.length;
|
|
516
|
+
else if (g3 && g3[0] === "#") result.maximumFractionDigits = g3.length;
|
|
517
|
+
else if (g4 && g5) {
|
|
518
|
+
result.minimumFractionDigits = g4.length;
|
|
519
|
+
result.maximumFractionDigits = g4.length + g5.length;
|
|
520
|
+
} else {
|
|
521
|
+
result.minimumFractionDigits = g1.length;
|
|
522
|
+
result.maximumFractionDigits = g1.length;
|
|
523
|
+
}
|
|
524
|
+
return "";
|
|
525
|
+
});
|
|
526
|
+
var opt = token.options[0];
|
|
527
|
+
if (opt === "w") result = _objectSpreadProps(_objectSpread({}, result), {
|
|
528
|
+
trailingZeroDisplay: "stripIfInteger"
|
|
529
|
+
});
|
|
530
|
+
else if (opt) result = _objectSpread({}, result, parseSignificantPrecision(opt));
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) {
|
|
534
|
+
result = _objectSpread({}, result, parseSignificantPrecision(token.stem));
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
var signOpts = parseSign(token.stem);
|
|
538
|
+
if (signOpts) result = _objectSpread({}, result, signOpts);
|
|
539
|
+
var conciseScientificAndEngineeringOpts = parseConciseScientificAndEngineeringStem(token.stem);
|
|
540
|
+
if (conciseScientificAndEngineeringOpts) result = _objectSpread({}, result, conciseScientificAndEngineeringOpts);
|
|
541
|
+
}
|
|
542
|
+
} catch (err) {
|
|
543
|
+
_didIteratorError = true;
|
|
544
|
+
_iteratorError = err;
|
|
545
|
+
} finally{
|
|
546
|
+
try {
|
|
547
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
548
|
+
_iterator.return();
|
|
549
|
+
}
|
|
550
|
+
} finally{
|
|
551
|
+
if (_didIteratorError) {
|
|
552
|
+
throw _iteratorError;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return result;
|
|
557
|
+
}
|
|
558
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../date-time.ts","../../../node_modules/.aspect_rules_js/@formatjs_generated+unicode@0.0.0/node_modules/@formatjs_generated/unicode/icu-skeleton-parser-regex.js","../number.ts"],"sourcesContent":["/**\n * https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table\n * Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js\n * with some tweaks\n */\nconst DATE_TIME_REGEX =\n /(?:[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\n\n/**\n * Parse Date time skeleton into Intl.DateTimeFormatOptions\n * Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table\n * @public\n * @param skeleton skeleton string\n */\nexport function parseDateTimeSkeleton(\n skeleton: string\n): Intl.DateTimeFormatOptions {\n const result: Intl.DateTimeFormatOptions = {}\n skeleton.replace(DATE_TIME_REGEX, match => {\n const len = match.length\n switch (match[0]) {\n // Era\n case 'G':\n result.era = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short'\n break\n // Year\n case 'y':\n result.year = len === 2 ? '2-digit' : 'numeric'\n break\n case 'Y':\n case 'u':\n case 'U':\n case 'r':\n throw new RangeError(\n '`Y/u/U/r` (year) patterns are not supported, use `y` instead'\n )\n // Quarter\n case 'q':\n case 'Q':\n throw new RangeError('`q/Q` (quarter) patterns are not supported')\n // Month\n case 'M':\n case 'L':\n result.month = ['numeric', '2-digit', 'short', 'long', 'narrow'][\n len - 1\n ] as 'numeric'\n break\n // Week\n case 'w':\n case 'W':\n throw new RangeError('`w/W` (week) patterns are not supported')\n case 'd':\n result.day = ['numeric', '2-digit'][len - 1] as 'numeric'\n break\n case 'D':\n case 'F':\n case 'g':\n throw new RangeError(\n '`D/F/g` (day) patterns are not supported, use `d` instead'\n )\n // Weekday\n case 'E':\n result.weekday = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short'\n break\n case 'e':\n if (len < 4) {\n throw new RangeError('`e..eee` (weekday) patterns are not supported')\n }\n result.weekday = ['short', 'long', 'narrow', 'short'][\n len - 4\n ] as 'short'\n break\n case 'c':\n if (len < 4) {\n throw new RangeError('`c..ccc` (weekday) patterns are not supported')\n }\n result.weekday = ['short', 'long', 'narrow', 'short'][\n len - 4\n ] as 'short'\n break\n\n // Period\n case 'a': // AM, PM\n result.hour12 = true\n break\n case 'b': // am, pm, noon, midnight\n case 'B': // flexible day periods\n throw new RangeError(\n '`b/B` (period) patterns are not supported, use `a` instead'\n )\n // Hour\n case 'h':\n result.hourCycle = 'h12'\n result.hour = ['numeric', '2-digit'][len - 1] as 'numeric'\n break\n case 'H':\n result.hourCycle = 'h23'\n result.hour = ['numeric', '2-digit'][len - 1] as 'numeric'\n break\n case 'K':\n result.hourCycle = 'h11'\n result.hour = ['numeric', '2-digit'][len - 1] as 'numeric'\n break\n case 'k':\n result.hourCycle = 'h24'\n result.hour = ['numeric', '2-digit'][len - 1] as 'numeric'\n break\n case 'j':\n case 'J':\n case 'C':\n throw new RangeError(\n '`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead'\n )\n // Minute\n case 'm':\n result.minute = ['numeric', '2-digit'][len - 1] as 'numeric'\n break\n // Second\n case 's':\n result.second = ['numeric', '2-digit'][len - 1] as 'numeric'\n break\n case 'S':\n case 'A':\n throw new RangeError(\n '`S/A` (second) patterns are not supported, use `s` instead'\n )\n // Zone\n case 'z': // 1..3, 4: specific non-location format\n result.timeZoneName = len < 4 ? 'short' : 'long'\n break\n case 'Z': // 1..3, 4, 5: The ISO8601 varios formats\n case 'O': // 1, 4: milliseconds in day short, long\n case 'v': // 1, 4: generic non-location format\n case 'V': // 1, 2, 3, 4: time zone ID or city\n case 'X': // 1, 2, 3, 4: The ISO8601 varios formats\n case 'x': // 1, 2, 3, 4: The ISO8601 varios formats\n throw new RangeError(\n '`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead'\n )\n }\n return ''\n })\n return result\n}\n","// @generated from regex-gen.ts\nexport const WHITE_SPACE_REGEX = /[\\t-\\r \\x85\\u200E\\u200F\\u2028\\u2029]/i;\n","import type {NumberFormatOptions} from '#packages/ecma402-abstract/types/number.js'\nimport {WHITE_SPACE_REGEX} from '@formatjs_generated/unicode/icu-skeleton-parser-regex.js'\n\nexport interface ExtendedNumberFormatOptions extends NumberFormatOptions {\n scale?: number\n}\nexport interface NumberSkeletonToken {\n stem: string\n options: string[]\n}\n\nexport function parseNumberSkeletonFromString(\n skeleton: string\n): NumberSkeletonToken[] {\n if (skeleton.length === 0) {\n throw new Error('Number skeleton cannot be empty')\n }\n // Parse the skeleton\n const stringTokens = skeleton\n .split(WHITE_SPACE_REGEX)\n .filter(x => x.length > 0)\n\n const tokens: NumberSkeletonToken[] = []\n for (const stringToken of stringTokens) {\n let stemAndOptions = stringToken.split('/')\n if (stemAndOptions.length === 0) {\n throw new Error('Invalid number skeleton')\n }\n\n const [stem, ...options] = stemAndOptions\n for (const option of options) {\n if (option.length === 0) {\n throw new Error('Invalid number skeleton')\n }\n }\n\n tokens.push({stem, options})\n }\n return tokens\n}\n\nfunction icuUnitToEcma(unit: string): ExtendedNumberFormatOptions['unit'] {\n return unit.replace(/^(.*?)-/, '') as ExtendedNumberFormatOptions['unit']\n}\n\nconst FRACTION_PRECISION_REGEX = /^\\.(?:(0+)(\\*)?|(#+)|(0+)(#+))$/g\nconst SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\\+|#+)?[rs]?$/g\nconst INTEGER_WIDTH_REGEX = /(\\*)(0+)|(#+)(0+)|(0+)/g\nconst CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/\n\nfunction parseSignificantPrecision(str: string): ExtendedNumberFormatOptions {\n const result: ExtendedNumberFormatOptions = {}\n if (str[str.length - 1] === 'r') {\n result.roundingPriority = 'morePrecision'\n } else if (str[str.length - 1] === 's') {\n result.roundingPriority = 'lessPrecision'\n }\n str.replace(\n SIGNIFICANT_PRECISION_REGEX,\n function (_: string, g1: string, g2: string | number) {\n // @@@ case\n if (typeof g2 !== 'string') {\n result.minimumSignificantDigits = g1.length\n result.maximumSignificantDigits = g1.length\n }\n // @@@+ case\n else if (g2 === '+') {\n result.minimumSignificantDigits = g1.length\n }\n // .### case\n else if (g1[0] === '#') {\n result.maximumSignificantDigits = g1.length\n }\n // .@@## or .@@@ case\n else {\n result.minimumSignificantDigits = g1.length\n result.maximumSignificantDigits =\n g1.length + (typeof g2 === 'string' ? g2.length : 0)\n }\n return ''\n }\n )\n return result\n}\n\nfunction parseSign(str: string): ExtendedNumberFormatOptions | undefined {\n switch (str) {\n case 'sign-auto':\n return {\n signDisplay: 'auto',\n }\n case 'sign-accounting':\n case '()':\n return {\n currencySign: 'accounting',\n }\n case 'sign-always':\n case '+!':\n return {\n signDisplay: 'always',\n }\n case 'sign-accounting-always':\n case '()!':\n return {\n signDisplay: 'always',\n currencySign: 'accounting',\n }\n case 'sign-except-zero':\n case '+?':\n return {\n signDisplay: 'exceptZero',\n }\n case 'sign-accounting-except-zero':\n case '()?':\n return {\n signDisplay: 'exceptZero',\n currencySign: 'accounting',\n }\n case 'sign-never':\n case '+_':\n return {\n signDisplay: 'never',\n }\n }\n}\n\nfunction parseConciseScientificAndEngineeringStem(\n stem: string\n): ExtendedNumberFormatOptions | undefined {\n // Engineering\n let result: ExtendedNumberFormatOptions | undefined\n if (stem[0] === 'E' && stem[1] === 'E') {\n result = {\n notation: 'engineering',\n }\n stem = stem.slice(2)\n } else if (stem[0] === 'E') {\n result = {\n notation: 'scientific',\n }\n stem = stem.slice(1)\n }\n if (result) {\n const signDisplay = stem.slice(0, 2)\n if (signDisplay === '+!') {\n result.signDisplay = 'always'\n stem = stem.slice(2)\n } else if (signDisplay === '+?') {\n result.signDisplay = 'exceptZero'\n stem = stem.slice(2)\n }\n if (!CONCISE_INTEGER_WIDTH_REGEX.test(stem)) {\n throw new Error('Malformed concise eng/scientific notation')\n }\n result.minimumIntegerDigits = stem.length\n }\n return result\n}\n\nfunction parseNotationOptions(opt: string): ExtendedNumberFormatOptions {\n const result: ExtendedNumberFormatOptions = {}\n const signOpts = parseSign(opt)\n if (signOpts) {\n return signOpts\n }\n return result\n}\n\n/**\n * https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options\n */\nexport function parseNumberSkeleton(\n tokens: NumberSkeletonToken[]\n): ExtendedNumberFormatOptions {\n let result: ExtendedNumberFormatOptions = {}\n for (const token of tokens) {\n switch (token.stem) {\n case 'percent':\n case '%':\n result.style = 'percent'\n continue\n case '%x100':\n result.style = 'percent'\n result.scale = 100\n continue\n case 'currency':\n result.style = 'currency'\n result.currency = token.options[0]\n continue\n case 'group-off':\n case ',_':\n result.useGrouping = false\n continue\n case 'precision-integer':\n case '.':\n result.maximumFractionDigits = 0\n continue\n case 'measure-unit':\n case 'unit':\n result.style = 'unit'\n result.unit = icuUnitToEcma(token.options[0])\n continue\n case 'compact-short':\n case 'K':\n result.notation = 'compact'\n result.compactDisplay = 'short'\n continue\n case 'compact-long':\n case 'KK':\n result.notation = 'compact'\n result.compactDisplay = 'long'\n continue\n case 'scientific':\n result = {\n ...result,\n notation: 'scientific',\n ...token.options.reduce(\n (all, opt) => ({...all, ...parseNotationOptions(opt)}),\n {}\n ),\n }\n continue\n case 'engineering':\n result = {\n ...result,\n notation: 'engineering',\n ...token.options.reduce(\n (all, opt) => ({...all, ...parseNotationOptions(opt)}),\n {}\n ),\n }\n continue\n case 'notation-simple':\n result.notation = 'standard'\n continue\n // https://github.com/unicode-org/icu/blob/master/icu4c/source/i18n/unicode/unumberformatter.h\n case 'unit-width-narrow':\n result.currencyDisplay = 'narrowSymbol'\n result.unitDisplay = 'narrow'\n continue\n case 'unit-width-short':\n result.currencyDisplay = 'code'\n result.unitDisplay = 'short'\n continue\n case 'unit-width-full-name':\n result.currencyDisplay = 'name'\n result.unitDisplay = 'long'\n continue\n case 'unit-width-iso-code':\n result.currencyDisplay = 'symbol'\n continue\n case 'scale':\n result.scale = parseFloat(token.options[0])\n continue\n case 'rounding-mode-floor':\n result.roundingMode = 'floor'\n continue\n case 'rounding-mode-ceiling':\n result.roundingMode = 'ceil'\n continue\n case 'rounding-mode-down':\n result.roundingMode = 'trunc'\n continue\n case 'rounding-mode-up':\n result.roundingMode = 'expand'\n continue\n case 'rounding-mode-half-even':\n result.roundingMode = 'halfEven'\n continue\n case 'rounding-mode-half-down':\n result.roundingMode = 'halfTrunc'\n continue\n case 'rounding-mode-half-up':\n result.roundingMode = 'halfExpand'\n continue\n // https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width\n case 'integer-width':\n if (token.options.length > 1) {\n throw new RangeError(\n 'integer-width stems only accept a single optional option'\n )\n }\n token.options[0].replace(\n INTEGER_WIDTH_REGEX,\n function (\n _: string,\n g1: string,\n g2: string,\n g3: string,\n g4: string,\n g5: string\n ) {\n if (g1) {\n result.minimumIntegerDigits = g2.length\n } else if (g3 && g4) {\n throw new Error(\n 'We currently do not support maximum integer digits'\n )\n } else if (g5) {\n throw new Error(\n 'We currently do not support exact integer digits'\n )\n }\n return ''\n }\n )\n continue\n }\n // https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width\n if (CONCISE_INTEGER_WIDTH_REGEX.test(token.stem)) {\n result.minimumIntegerDigits = token.stem.length\n continue\n }\n if (FRACTION_PRECISION_REGEX.test(token.stem)) {\n // Precision\n // https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#fraction-precision\n // precision-integer case\n if (token.options.length > 1) {\n throw new RangeError(\n 'Fraction-precision stems only accept a single optional option'\n )\n }\n token.stem.replace(\n FRACTION_PRECISION_REGEX,\n function (\n _: string,\n g1: string,\n g2: string | number,\n g3: string,\n g4: string,\n g5: string\n ) {\n // .000* case (before ICU67 it was .000+)\n if (g2 === '*') {\n result.minimumFractionDigits = g1.length\n }\n // .### case\n else if (g3 && g3[0] === '#') {\n result.maximumFractionDigits = g3.length\n }\n // .00## case\n else if (g4 && g5) {\n result.minimumFractionDigits = g4.length\n result.maximumFractionDigits = g4.length + g5.length\n } else {\n result.minimumFractionDigits = g1.length\n result.maximumFractionDigits = g1.length\n }\n return ''\n }\n )\n\n const opt = token.options[0]\n // https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#trailing-zero-display\n if (opt === 'w') {\n result = {...result, trailingZeroDisplay: 'stripIfInteger'}\n } else if (opt) {\n result = {...result, ...parseSignificantPrecision(opt)}\n }\n continue\n }\n // https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#significant-digits-precision\n if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) {\n result = {...result, ...parseSignificantPrecision(token.stem)}\n continue\n }\n const signOpts = parseSign(token.stem)\n if (signOpts) {\n result = {...result, ...signOpts}\n }\n const conciseScientificAndEngineeringOpts =\n parseConciseScientificAndEngineeringStem(token.stem)\n if (conciseScientificAndEngineeringOpts) {\n result = {...result, ...conciseScientificAndEngineeringOpts}\n }\n }\n return result\n}\n"],"x_google_ignoreList":[1],"mappings":";;;;;;AAKA,MAAM,kBACJ;;;;;;;AAQF,SAAgB,sBACd,UAC4B;CAC5B,MAAM,SAAqC,CAAC;CAC5C,SAAS,QAAQ,kBAAiB,UAAS;EACzC,MAAM,MAAM,MAAM;EAClB,QAAQ,MAAM,IAAd;GAEE,KAAK;IACH,OAAO,MAAM,QAAQ,IAAI,SAAS,QAAQ,IAAI,WAAW;IACzD;GAEF,KAAK;IACH,OAAO,OAAO,QAAQ,IAAI,YAAY;IACtC;GACF,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK,KACH,MAAM,IAAI,WACR,8DACF;GAEF,KAAK;GACL,KAAK,KACH,MAAM,IAAI,WAAW,4CAA4C;GAEnE,KAAK;GACL,KAAK;IACH,OAAO,QAAQ;KAAC;KAAW;KAAW;KAAS;KAAQ;IAAQ,EAC7D,MAAM;IAER;GAEF,KAAK;GACL,KAAK,KACH,MAAM,IAAI,WAAW,yCAAyC;GAChE,KAAK;IACH,OAAO,MAAM,CAAC,WAAW,SAAS,EAAE,MAAM;IAC1C;GACF,KAAK;GACL,KAAK;GACL,KAAK,KACH,MAAM,IAAI,WACR,2DACF;GAEF,KAAK;IACH,OAAO,UAAU,QAAQ,IAAI,SAAS,QAAQ,IAAI,WAAW;IAC7D;GACF,KAAK;IACH,IAAI,MAAM,GACR,MAAM,IAAI,WAAW,+CAA+C;IAEtE,OAAO,UAAU;KAAC;KAAS;KAAQ;KAAU;IAAO,EAClD,MAAM;IAER;GACF,K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eleton-parser",
|
|
3
|
+
"version": "2.1.10",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": "etienne-martin/common.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"homepage": "https://github.com/etienne-martin/common.js#readme",
|
|
9
|
+
"description": "@formatjs/icu-skeleton-parser package exported as CommonJS modules",
|
|
10
|
+
"dependencies": {},
|
|
11
|
+
"scripts": {},
|
|
12
|
+
"main": "./index.js"
|
|
13
|
+
}
|