@formatjs/icu-skeleton-parser 1.2.11 → 1.3.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.js +2 -2
- package/lib/number.d.ts.map +1 -1
- package/lib/number.js +14 -3
- package/number.d.ts.map +1 -1
- package/number.js +19 -8
- package/package.json +7 -2
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./date-time"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./number"), exports);
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./date-time"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./number"), exports);
|
package/lib/number.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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
CHANGED
|
@@ -30,11 +30,17 @@ function icuUnitToEcma(unit) {
|
|
|
30
30
|
return unit.replace(/^(.*?)-/, '');
|
|
31
31
|
}
|
|
32
32
|
var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
|
|
33
|
-
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?$/g;
|
|
33
|
+
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?[rs]?$/g;
|
|
34
34
|
var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
|
|
35
35
|
var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
|
|
36
36
|
function parseSignificantPrecision(str) {
|
|
37
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
|
+
}
|
|
38
44
|
str.replace(SIGNIFICANT_PRECISION_REGEX, function (_, g1, g2) {
|
|
39
45
|
// @@@ case
|
|
40
46
|
if (typeof g2 !== 'string') {
|
|
@@ -261,8 +267,13 @@ export function parseNumberSkeleton(tokens) {
|
|
|
261
267
|
}
|
|
262
268
|
return '';
|
|
263
269
|
});
|
|
264
|
-
|
|
265
|
-
|
|
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));
|
|
266
277
|
}
|
|
267
278
|
continue;
|
|
268
279
|
}
|
package/number.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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/number.js
CHANGED
|
@@ -34,11 +34,17 @@ function icuUnitToEcma(unit) {
|
|
|
34
34
|
return unit.replace(/^(.*?)-/, '');
|
|
35
35
|
}
|
|
36
36
|
var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
|
|
37
|
-
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?$/g;
|
|
37
|
+
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?[rs]?$/g;
|
|
38
38
|
var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
|
|
39
39
|
var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
|
|
40
40
|
function parseSignificantPrecision(str) {
|
|
41
41
|
var result = {};
|
|
42
|
+
if (str[str.length - 1] === 'r') {
|
|
43
|
+
result.roundingPriority = 'morePrecision';
|
|
44
|
+
}
|
|
45
|
+
else if (str[str.length - 1] === 's') {
|
|
46
|
+
result.roundingPriority = 'lessPrecision';
|
|
47
|
+
}
|
|
42
48
|
str.replace(SIGNIFICANT_PRECISION_REGEX, function (_, g1, g2) {
|
|
43
49
|
// @@@ case
|
|
44
50
|
if (typeof g2 !== 'string') {
|
|
@@ -187,10 +193,10 @@ function parseNumberSkeleton(tokens) {
|
|
|
187
193
|
result.compactDisplay = 'long';
|
|
188
194
|
continue;
|
|
189
195
|
case 'scientific':
|
|
190
|
-
result = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, result), { notation: 'scientific' }), token.options.reduce(function (all, opt) { return (tslib_1.__assign(tslib_1.__assign({}, all), parseNotationOptions(opt))); }, {}));
|
|
196
|
+
result = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, result), { notation: 'scientific' }), token.options.reduce(function (all, opt) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, all), parseNotationOptions(opt))); }, {}));
|
|
191
197
|
continue;
|
|
192
198
|
case 'engineering':
|
|
193
|
-
result = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, result), { notation: 'engineering' }), token.options.reduce(function (all, opt) { return (tslib_1.__assign(tslib_1.__assign({}, all), parseNotationOptions(opt))); }, {}));
|
|
199
|
+
result = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, result), { notation: 'engineering' }), token.options.reduce(function (all, opt) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, all), parseNotationOptions(opt))); }, {}));
|
|
194
200
|
continue;
|
|
195
201
|
case 'notation-simple':
|
|
196
202
|
result.notation = 'standard';
|
|
@@ -265,23 +271,28 @@ function parseNumberSkeleton(tokens) {
|
|
|
265
271
|
}
|
|
266
272
|
return '';
|
|
267
273
|
});
|
|
268
|
-
|
|
269
|
-
|
|
274
|
+
var opt = token.options[0];
|
|
275
|
+
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#trailing-zero-display
|
|
276
|
+
if (opt === 'w') {
|
|
277
|
+
result = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, result), { trailingZeroDisplay: 'stripIfInteger' });
|
|
278
|
+
}
|
|
279
|
+
else if (opt) {
|
|
280
|
+
result = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, result), parseSignificantPrecision(opt));
|
|
270
281
|
}
|
|
271
282
|
continue;
|
|
272
283
|
}
|
|
273
284
|
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#significant-digits-precision
|
|
274
285
|
if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) {
|
|
275
|
-
result = tslib_1.__assign(tslib_1.__assign({}, result), parseSignificantPrecision(token.stem));
|
|
286
|
+
result = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, result), parseSignificantPrecision(token.stem));
|
|
276
287
|
continue;
|
|
277
288
|
}
|
|
278
289
|
var signOpts = parseSign(token.stem);
|
|
279
290
|
if (signOpts) {
|
|
280
|
-
result = tslib_1.__assign(tslib_1.__assign({}, result), signOpts);
|
|
291
|
+
result = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, result), signOpts);
|
|
281
292
|
}
|
|
282
293
|
var conciseScientificAndEngineeringOpts = parseConciseScientificAndEngineeringStem(token.stem);
|
|
283
294
|
if (conciseScientificAndEngineeringOpts) {
|
|
284
|
-
result = tslib_1.__assign(tslib_1.__assign({}, result), conciseScientificAndEngineeringOpts);
|
|
295
|
+
result = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, result), conciseScientificAndEngineeringOpts);
|
|
285
296
|
}
|
|
286
297
|
}
|
|
287
298
|
return result;
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/icu-skeleton-parser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/formatjs/formatjs.git",
|
|
11
|
+
"directory": "packages/icu-skeleton-parser"
|
|
12
|
+
},
|
|
8
13
|
"dependencies": {
|
|
9
|
-
"@formatjs/ecma402-abstract": "1.
|
|
14
|
+
"@formatjs/ecma402-abstract": "1.10.0",
|
|
10
15
|
"tslib": "^2.1.0"
|
|
11
16
|
}
|
|
12
17
|
}
|