@formatjs/icu-messageformat-parser 2.7.0 → 2.7.2
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/error.js +1 -1
- package/lib/date-time-pattern-generator.js +10 -6
- package/lib/error.js +5 -2
- package/lib/index.js +19 -15
- package/lib/manipulator.js +12 -8
- package/lib/no-parser.js +8 -3
- package/lib/parser.js +60 -57
- package/lib/printer.js +21 -15
- package/lib/regex.generated.js +5 -2
- package/lib/time-data.generated.js +4 -1
- package/lib/types.js +33 -17
- package/package.json +3 -3
- package/types.js +2 -2
package/error.js
CHANGED
|
@@ -63,4 +63,4 @@ var ErrorKind;
|
|
|
63
63
|
ErrorKind[ErrorKind["UNMATCHED_CLOSING_TAG"] = 26] = "UNMATCHED_CLOSING_TAG";
|
|
64
64
|
/** The opening tag has unmatched closing tag. (e.g. `<bold>foo`) */
|
|
65
65
|
ErrorKind[ErrorKind["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG";
|
|
66
|
-
})(ErrorKind
|
|
66
|
+
})(ErrorKind || (exports.ErrorKind = ErrorKind = {}));
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBestPattern = void 0;
|
|
4
|
+
var time_data_generated_1 = require("./time-data.generated");
|
|
2
5
|
/**
|
|
3
6
|
* Returns the best matching date time pattern if a date time skeleton
|
|
4
7
|
* pattern is provided with a locale. Follows the Unicode specification:
|
|
@@ -6,7 +9,7 @@ import { timeData } from './time-data.generated';
|
|
|
6
9
|
* @param skeleton date time skeleton pattern that possibly includes j, J or C
|
|
7
10
|
* @param locale
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
function getBestPattern(skeleton, locale) {
|
|
10
13
|
var skeletonCopy = '';
|
|
11
14
|
for (var patternPos = 0; patternPos < skeleton.length; patternPos++) {
|
|
12
15
|
var patternChar = skeleton.charAt(patternPos);
|
|
@@ -40,6 +43,7 @@ export function getBestPattern(skeleton, locale) {
|
|
|
40
43
|
}
|
|
41
44
|
return skeletonCopy;
|
|
42
45
|
}
|
|
46
|
+
exports.getBestPattern = getBestPattern;
|
|
43
47
|
/**
|
|
44
48
|
* Maps the [hour cycle type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
|
|
45
49
|
* of the given `locale` to the corresponding time pattern.
|
|
@@ -75,9 +79,9 @@ function getDefaultHourSymbolFromLocale(locale) {
|
|
|
75
79
|
if (languageTag !== 'root') {
|
|
76
80
|
regionTag = locale.maximize().region;
|
|
77
81
|
}
|
|
78
|
-
var hourCycles = timeData[regionTag || ''] ||
|
|
79
|
-
timeData[languageTag || ''] ||
|
|
80
|
-
timeData["".concat(languageTag, "-001")] ||
|
|
81
|
-
timeData['001'];
|
|
82
|
+
var hourCycles = time_data_generated_1.timeData[regionTag || ''] ||
|
|
83
|
+
time_data_generated_1.timeData[languageTag || ''] ||
|
|
84
|
+
time_data_generated_1.timeData["".concat(languageTag, "-001")] ||
|
|
85
|
+
time_data_generated_1.timeData['001'];
|
|
82
86
|
return hourCycles[0];
|
|
83
87
|
}
|
package/lib/error.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorKind = void 0;
|
|
4
|
+
var ErrorKind;
|
|
2
5
|
(function (ErrorKind) {
|
|
3
6
|
/** Argument is unclosed (e.g. `{0`) */
|
|
4
7
|
ErrorKind[ErrorKind["EXPECT_ARGUMENT_CLOSING_BRACE"] = 1] = "EXPECT_ARGUMENT_CLOSING_BRACE";
|
|
@@ -60,4 +63,4 @@ export var ErrorKind;
|
|
|
60
63
|
ErrorKind[ErrorKind["UNMATCHED_CLOSING_TAG"] = 26] = "UNMATCHED_CLOSING_TAG";
|
|
61
64
|
/** The opening tag has unmatched closing tag. (e.g. `<bold>foo`) */
|
|
62
65
|
ErrorKind[ErrorKind["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG";
|
|
63
|
-
})(ErrorKind || (ErrorKind = {}));
|
|
66
|
+
})(ErrorKind || (exports.ErrorKind = ErrorKind = {}));
|
package/lib/index.js
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._Parser = exports.parse = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var error_1 = require("./error");
|
|
6
|
+
var parser_1 = require("./parser");
|
|
7
|
+
var types_1 = require("./types");
|
|
5
8
|
function pruneLocation(els) {
|
|
6
9
|
els.forEach(function (el) {
|
|
7
10
|
delete el.location;
|
|
8
|
-
if (isSelectElement(el) || isPluralElement(el)) {
|
|
11
|
+
if ((0, types_1.isSelectElement)(el) || (0, types_1.isPluralElement)(el)) {
|
|
9
12
|
for (var k in el.options) {
|
|
10
13
|
delete el.options[k].location;
|
|
11
14
|
pruneLocation(el.options[k].value);
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
|
-
else if (isNumberElement(el) && isNumberSkeleton(el.style)) {
|
|
17
|
+
else if ((0, types_1.isNumberElement)(el) && (0, types_1.isNumberSkeleton)(el.style)) {
|
|
15
18
|
delete el.style.location;
|
|
16
19
|
}
|
|
17
|
-
else if ((isDateElement(el) || isTimeElement(el)) &&
|
|
18
|
-
isDateTimeSkeleton(el.style)) {
|
|
20
|
+
else if (((0, types_1.isDateElement)(el) || (0, types_1.isTimeElement)(el)) &&
|
|
21
|
+
(0, types_1.isDateTimeSkeleton)(el.style)) {
|
|
19
22
|
delete el.style.location;
|
|
20
23
|
}
|
|
21
|
-
else if (isTagElement(el)) {
|
|
24
|
+
else if ((0, types_1.isTagElement)(el)) {
|
|
22
25
|
pruneLocation(el.children);
|
|
23
26
|
}
|
|
24
27
|
});
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
function parse(message, opts) {
|
|
27
30
|
if (opts === void 0) { opts = {}; }
|
|
28
|
-
opts = __assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts);
|
|
29
|
-
var result = new Parser(message, opts).parse();
|
|
31
|
+
opts = tslib_1.__assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts);
|
|
32
|
+
var result = new parser_1.Parser(message, opts).parse();
|
|
30
33
|
if (result.err) {
|
|
31
|
-
var error = SyntaxError(ErrorKind[result.err.kind]);
|
|
34
|
+
var error = SyntaxError(error_1.ErrorKind[result.err.kind]);
|
|
32
35
|
// @ts-expect-error Assign to error object
|
|
33
36
|
error.location = result.err.location;
|
|
34
37
|
// @ts-expect-error Assign to error object
|
|
@@ -40,6 +43,7 @@ export function parse(message, opts) {
|
|
|
40
43
|
}
|
|
41
44
|
return result.val;
|
|
42
45
|
}
|
|
43
|
-
|
|
46
|
+
exports.parse = parse;
|
|
47
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
44
48
|
// only for testing
|
|
45
|
-
|
|
49
|
+
exports._Parser = parser_1.Parser;
|
package/lib/manipulator.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hoistSelectors = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var types_1 = require("./types");
|
|
3
6
|
function cloneDeep(obj) {
|
|
4
7
|
if (Array.isArray(obj)) {
|
|
5
8
|
// @ts-expect-error meh
|
|
6
|
-
return __spreadArray([], obj.map(cloneDeep), true);
|
|
9
|
+
return tslib_1.__spreadArray([], obj.map(cloneDeep), true);
|
|
7
10
|
}
|
|
8
11
|
if (obj !== null && typeof obj === 'object') {
|
|
9
12
|
// @ts-expect-error meh
|
|
@@ -20,7 +23,7 @@ function hoistPluralOrSelectElement(ast, el, positionToInject) {
|
|
|
20
23
|
var cloned = cloneDeep(el);
|
|
21
24
|
var options = cloned.options;
|
|
22
25
|
cloned.options = Object.keys(options).reduce(function (all, k) {
|
|
23
|
-
var newValue = hoistSelectors(__spreadArray(__spreadArray(__spreadArray([], ast.slice(0, positionToInject), true), options[k].value, true), ast.slice(positionToInject + 1), true));
|
|
26
|
+
var newValue = hoistSelectors(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], ast.slice(0, positionToInject), true), options[k].value, true), ast.slice(positionToInject + 1), true));
|
|
24
27
|
all[k] = {
|
|
25
28
|
value: newValue,
|
|
26
29
|
};
|
|
@@ -29,14 +32,14 @@ function hoistPluralOrSelectElement(ast, el, positionToInject) {
|
|
|
29
32
|
return cloned;
|
|
30
33
|
}
|
|
31
34
|
function isPluralOrSelectElement(el) {
|
|
32
|
-
return isPluralElement(el) || isSelectElement(el);
|
|
35
|
+
return (0, types_1.isPluralElement)(el) || (0, types_1.isSelectElement)(el);
|
|
33
36
|
}
|
|
34
37
|
function findPluralOrSelectElement(ast) {
|
|
35
38
|
return !!ast.find(function (el) {
|
|
36
39
|
if (isPluralOrSelectElement(el)) {
|
|
37
40
|
return true;
|
|
38
41
|
}
|
|
39
|
-
if (isTagElement(el)) {
|
|
42
|
+
if ((0, types_1.isTagElement)(el)) {
|
|
40
43
|
return findPluralOrSelectElement(el.children);
|
|
41
44
|
}
|
|
42
45
|
return false;
|
|
@@ -53,15 +56,16 @@ function findPluralOrSelectElement(ast) {
|
|
|
53
56
|
* sentences are not translator-friendly
|
|
54
57
|
* @param ast AST
|
|
55
58
|
*/
|
|
56
|
-
|
|
59
|
+
function hoistSelectors(ast) {
|
|
57
60
|
for (var i = 0; i < ast.length; i++) {
|
|
58
61
|
var el = ast[i];
|
|
59
62
|
if (isPluralOrSelectElement(el)) {
|
|
60
63
|
return [hoistPluralOrSelectElement(ast, el, i)];
|
|
61
64
|
}
|
|
62
|
-
if (isTagElement(el) && findPluralOrSelectElement([el])) {
|
|
65
|
+
if ((0, types_1.isTagElement)(el) && findPluralOrSelectElement([el])) {
|
|
63
66
|
throw new Error('Cannot hoist plural/select within a tag element. Please put the tag element inside each plural/select option');
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
return ast;
|
|
67
70
|
}
|
|
71
|
+
exports.hoistSelectors = hoistSelectors;
|
package/lib/no-parser.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._Parser = exports.parse = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
function parse() {
|
|
2
6
|
throw new Error("You're trying to format an uncompiled message with react-intl without parser, please import from 'react-intl' instead");
|
|
3
7
|
}
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
exports.parse = parse;
|
|
9
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
10
|
+
exports._Parser = undefined;
|
package/lib/parser.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var _a;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Parser = void 0;
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
var error_1 = require("./error");
|
|
7
|
+
var types_1 = require("./types");
|
|
8
|
+
var regex_generated_1 = require("./regex.generated");
|
|
9
|
+
var icu_skeleton_parser_1 = require("@formatjs/icu-skeleton-parser");
|
|
10
|
+
var date_time_pattern_generator_1 = require("./date-time-pattern-generator");
|
|
11
|
+
var SPACE_SEPARATOR_START_REGEX = new RegExp("^".concat(regex_generated_1.SPACE_SEPARATOR_REGEX.source, "*"));
|
|
12
|
+
var SPACE_SEPARATOR_END_REGEX = new RegExp("".concat(regex_generated_1.SPACE_SEPARATOR_REGEX.source, "*$"));
|
|
10
13
|
function createLocation(start, end) {
|
|
11
14
|
return { start: start, end: end };
|
|
12
15
|
}
|
|
@@ -192,7 +195,7 @@ var Parser = /** @class */ (function () {
|
|
|
192
195
|
var position = this.clonePosition();
|
|
193
196
|
this.bump();
|
|
194
197
|
elements.push({
|
|
195
|
-
type: TYPE.pound,
|
|
198
|
+
type: types_1.TYPE.pound,
|
|
196
199
|
location: createLocation(position, this.clonePosition()),
|
|
197
200
|
});
|
|
198
201
|
}
|
|
@@ -204,7 +207,7 @@ var Parser = /** @class */ (function () {
|
|
|
204
207
|
break;
|
|
205
208
|
}
|
|
206
209
|
else {
|
|
207
|
-
return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition()));
|
|
210
|
+
return this.error(error_1.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition()));
|
|
208
211
|
}
|
|
209
212
|
}
|
|
210
213
|
else if (char === 60 /* `<` */ &&
|
|
@@ -253,7 +256,7 @@ var Parser = /** @class */ (function () {
|
|
|
253
256
|
// Self closing tag
|
|
254
257
|
return {
|
|
255
258
|
val: {
|
|
256
|
-
type: TYPE.literal,
|
|
259
|
+
type: types_1.TYPE.literal,
|
|
257
260
|
value: "<".concat(tagName, "/>"),
|
|
258
261
|
location: createLocation(startPosition, this.clonePosition()),
|
|
259
262
|
},
|
|
@@ -270,20 +273,20 @@ var Parser = /** @class */ (function () {
|
|
|
270
273
|
var endTagStartPosition = this.clonePosition();
|
|
271
274
|
if (this.bumpIf('</')) {
|
|
272
275
|
if (this.isEOF() || !_isAlpha(this.char())) {
|
|
273
|
-
return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
|
|
276
|
+
return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
|
|
274
277
|
}
|
|
275
278
|
var closingTagNameStartPosition = this.clonePosition();
|
|
276
279
|
var closingTagName = this.parseTagName();
|
|
277
280
|
if (tagName !== closingTagName) {
|
|
278
|
-
return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition()));
|
|
281
|
+
return this.error(error_1.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition()));
|
|
279
282
|
}
|
|
280
283
|
this.bumpSpace();
|
|
281
284
|
if (!this.bumpIf('>')) {
|
|
282
|
-
return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
|
|
285
|
+
return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
|
|
283
286
|
}
|
|
284
287
|
return {
|
|
285
288
|
val: {
|
|
286
|
-
type: TYPE.tag,
|
|
289
|
+
type: types_1.TYPE.tag,
|
|
287
290
|
value: tagName,
|
|
288
291
|
children: children,
|
|
289
292
|
location: createLocation(startPosition, this.clonePosition()),
|
|
@@ -292,11 +295,11 @@ var Parser = /** @class */ (function () {
|
|
|
292
295
|
};
|
|
293
296
|
}
|
|
294
297
|
else {
|
|
295
|
-
return this.error(ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition()));
|
|
298
|
+
return this.error(error_1.ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition()));
|
|
296
299
|
}
|
|
297
300
|
}
|
|
298
301
|
else {
|
|
299
|
-
return this.error(ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition()));
|
|
302
|
+
return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition()));
|
|
300
303
|
}
|
|
301
304
|
};
|
|
302
305
|
/**
|
|
@@ -333,7 +336,7 @@ var Parser = /** @class */ (function () {
|
|
|
333
336
|
}
|
|
334
337
|
var location = createLocation(start, this.clonePosition());
|
|
335
338
|
return {
|
|
336
|
-
val: { type: TYPE.literal, value: value, location: location },
|
|
339
|
+
val: { type: types_1.TYPE.literal, value: value, location: location },
|
|
337
340
|
err: null,
|
|
338
341
|
};
|
|
339
342
|
};
|
|
@@ -426,20 +429,20 @@ var Parser = /** @class */ (function () {
|
|
|
426
429
|
this.bump(); // `{`
|
|
427
430
|
this.bumpSpace();
|
|
428
431
|
if (this.isEOF()) {
|
|
429
|
-
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
432
|
+
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
430
433
|
}
|
|
431
434
|
if (this.char() === 125 /* `}` */) {
|
|
432
435
|
this.bump();
|
|
433
|
-
return this.error(ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
|
|
436
|
+
return this.error(error_1.ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
|
|
434
437
|
}
|
|
435
438
|
// argument name
|
|
436
439
|
var value = this.parseIdentifierIfPossible().value;
|
|
437
440
|
if (!value) {
|
|
438
|
-
return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
|
|
441
|
+
return this.error(error_1.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
|
|
439
442
|
}
|
|
440
443
|
this.bumpSpace();
|
|
441
444
|
if (this.isEOF()) {
|
|
442
|
-
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
445
|
+
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
443
446
|
}
|
|
444
447
|
switch (this.char()) {
|
|
445
448
|
// Simple argument: `{name}`
|
|
@@ -447,7 +450,7 @@ var Parser = /** @class */ (function () {
|
|
|
447
450
|
this.bump(); // `}`
|
|
448
451
|
return {
|
|
449
452
|
val: {
|
|
450
|
-
type: TYPE.argument,
|
|
453
|
+
type: types_1.TYPE.argument,
|
|
451
454
|
// value does not include the opening and closing braces.
|
|
452
455
|
value: value,
|
|
453
456
|
location: createLocation(openingBracePosition, this.clonePosition()),
|
|
@@ -460,12 +463,12 @@ var Parser = /** @class */ (function () {
|
|
|
460
463
|
this.bump(); // `,`
|
|
461
464
|
this.bumpSpace();
|
|
462
465
|
if (this.isEOF()) {
|
|
463
|
-
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
466
|
+
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
464
467
|
}
|
|
465
468
|
return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition);
|
|
466
469
|
}
|
|
467
470
|
default:
|
|
468
|
-
return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
|
|
471
|
+
return this.error(error_1.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
|
|
469
472
|
}
|
|
470
473
|
};
|
|
471
474
|
/**
|
|
@@ -493,7 +496,7 @@ var Parser = /** @class */ (function () {
|
|
|
493
496
|
switch (argType) {
|
|
494
497
|
case '':
|
|
495
498
|
// Expecting a style string number, date, time, plural, selectordinal, or select.
|
|
496
|
-
return this.error(ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
|
|
499
|
+
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
|
|
497
500
|
case 'number':
|
|
498
501
|
case 'date':
|
|
499
502
|
case 'time': {
|
|
@@ -511,7 +514,7 @@ var Parser = /** @class */ (function () {
|
|
|
511
514
|
}
|
|
512
515
|
var style = trimEnd(result.val);
|
|
513
516
|
if (style.length === 0) {
|
|
514
|
-
return this.error(ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition()));
|
|
517
|
+
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition()));
|
|
515
518
|
}
|
|
516
519
|
var styleLocation = createLocation(styleStartPosition, this.clonePosition());
|
|
517
520
|
styleAndLocation = { style: style, styleLocation: styleLocation };
|
|
@@ -531,30 +534,30 @@ var Parser = /** @class */ (function () {
|
|
|
531
534
|
return result;
|
|
532
535
|
}
|
|
533
536
|
return {
|
|
534
|
-
val: { type: TYPE.number, value: value, location: location_1, style: result.val },
|
|
537
|
+
val: { type: types_1.TYPE.number, value: value, location: location_1, style: result.val },
|
|
535
538
|
err: null,
|
|
536
539
|
};
|
|
537
540
|
}
|
|
538
541
|
else {
|
|
539
542
|
if (skeleton.length === 0) {
|
|
540
|
-
return this.error(ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1);
|
|
543
|
+
return this.error(error_1.ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1);
|
|
541
544
|
}
|
|
542
545
|
var dateTimePattern = skeleton;
|
|
543
546
|
// Get "best match" pattern only if locale is passed, if not, let it
|
|
544
547
|
// pass as-is where `parseDateTimeSkeleton()` will throw an error
|
|
545
548
|
// for unsupported patterns.
|
|
546
549
|
if (this.locale) {
|
|
547
|
-
dateTimePattern = getBestPattern(skeleton, this.locale);
|
|
550
|
+
dateTimePattern = (0, date_time_pattern_generator_1.getBestPattern)(skeleton, this.locale);
|
|
548
551
|
}
|
|
549
552
|
var style = {
|
|
550
|
-
type: SKELETON_TYPE.dateTime,
|
|
553
|
+
type: types_1.SKELETON_TYPE.dateTime,
|
|
551
554
|
pattern: dateTimePattern,
|
|
552
555
|
location: styleAndLocation.styleLocation,
|
|
553
556
|
parsedOptions: this.shouldParseSkeletons
|
|
554
|
-
? parseDateTimeSkeleton(dateTimePattern)
|
|
557
|
+
? (0, icu_skeleton_parser_1.parseDateTimeSkeleton)(dateTimePattern)
|
|
555
558
|
: {},
|
|
556
559
|
};
|
|
557
|
-
var type = argType === 'date' ? TYPE.date : TYPE.time;
|
|
560
|
+
var type = argType === 'date' ? types_1.TYPE.date : types_1.TYPE.time;
|
|
558
561
|
return {
|
|
559
562
|
val: { type: type, value: value, location: location_1, style: style },
|
|
560
563
|
err: null,
|
|
@@ -565,10 +568,10 @@ var Parser = /** @class */ (function () {
|
|
|
565
568
|
return {
|
|
566
569
|
val: {
|
|
567
570
|
type: argType === 'number'
|
|
568
|
-
? TYPE.number
|
|
571
|
+
? types_1.TYPE.number
|
|
569
572
|
: argType === 'date'
|
|
570
|
-
? TYPE.date
|
|
571
|
-
: TYPE.time,
|
|
573
|
+
? types_1.TYPE.date
|
|
574
|
+
: types_1.TYPE.time,
|
|
572
575
|
value: value,
|
|
573
576
|
location: location_1,
|
|
574
577
|
style: (_a = styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style) !== null && _a !== void 0 ? _a : null,
|
|
@@ -585,7 +588,7 @@ var Parser = /** @class */ (function () {
|
|
|
585
588
|
var typeEndPosition_1 = this.clonePosition();
|
|
586
589
|
this.bumpSpace();
|
|
587
590
|
if (!this.bumpIf(',')) {
|
|
588
|
-
return this.error(ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, __assign({}, typeEndPosition_1)));
|
|
591
|
+
return this.error(error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, tslib_1.__assign({}, typeEndPosition_1)));
|
|
589
592
|
}
|
|
590
593
|
this.bumpSpace();
|
|
591
594
|
// Parse offset:
|
|
@@ -600,10 +603,10 @@ var Parser = /** @class */ (function () {
|
|
|
600
603
|
var pluralOffset = 0;
|
|
601
604
|
if (argType !== 'select' && identifierAndLocation.value === 'offset') {
|
|
602
605
|
if (!this.bumpIf(':')) {
|
|
603
|
-
return this.error(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition()));
|
|
606
|
+
return this.error(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition()));
|
|
604
607
|
}
|
|
605
608
|
this.bumpSpace();
|
|
606
|
-
var result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE);
|
|
609
|
+
var result = this.tryParseDecimalInteger(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, error_1.ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE);
|
|
607
610
|
if (result.err) {
|
|
608
611
|
return result;
|
|
609
612
|
}
|
|
@@ -624,7 +627,7 @@ var Parser = /** @class */ (function () {
|
|
|
624
627
|
if (argType === 'select') {
|
|
625
628
|
return {
|
|
626
629
|
val: {
|
|
627
|
-
type: TYPE.select,
|
|
630
|
+
type: types_1.TYPE.select,
|
|
628
631
|
value: value,
|
|
629
632
|
options: fromEntries(optionsResult.val),
|
|
630
633
|
location: location_2,
|
|
@@ -635,7 +638,7 @@ var Parser = /** @class */ (function () {
|
|
|
635
638
|
else {
|
|
636
639
|
return {
|
|
637
640
|
val: {
|
|
638
|
-
type: TYPE.plural,
|
|
641
|
+
type: types_1.TYPE.plural,
|
|
639
642
|
value: value,
|
|
640
643
|
options: fromEntries(optionsResult.val),
|
|
641
644
|
offset: pluralOffset,
|
|
@@ -647,14 +650,14 @@ var Parser = /** @class */ (function () {
|
|
|
647
650
|
}
|
|
648
651
|
}
|
|
649
652
|
default:
|
|
650
|
-
return this.error(ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
|
|
653
|
+
return this.error(error_1.ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
|
|
651
654
|
}
|
|
652
655
|
};
|
|
653
656
|
Parser.prototype.tryParseArgumentClose = function (openingBracePosition) {
|
|
654
657
|
// Parse: {value, number, ::currency/GBP }
|
|
655
658
|
//
|
|
656
659
|
if (this.isEOF() || this.char() !== 125 /* `}` */) {
|
|
657
|
-
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
660
|
+
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
658
661
|
}
|
|
659
662
|
this.bump(); // `}`
|
|
660
663
|
return { val: true, err: null };
|
|
@@ -674,7 +677,7 @@ var Parser = /** @class */ (function () {
|
|
|
674
677
|
this.bump();
|
|
675
678
|
var apostrophePosition = this.clonePosition();
|
|
676
679
|
if (!this.bumpUntil("'")) {
|
|
677
|
-
return this.error(ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition()));
|
|
680
|
+
return this.error(error_1.ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition()));
|
|
678
681
|
}
|
|
679
682
|
this.bump();
|
|
680
683
|
break;
|
|
@@ -709,18 +712,18 @@ var Parser = /** @class */ (function () {
|
|
|
709
712
|
Parser.prototype.parseNumberSkeletonFromString = function (skeleton, location) {
|
|
710
713
|
var tokens = [];
|
|
711
714
|
try {
|
|
712
|
-
tokens = parseNumberSkeletonFromString(skeleton);
|
|
715
|
+
tokens = (0, icu_skeleton_parser_1.parseNumberSkeletonFromString)(skeleton);
|
|
713
716
|
}
|
|
714
717
|
catch (e) {
|
|
715
|
-
return this.error(ErrorKind.INVALID_NUMBER_SKELETON, location);
|
|
718
|
+
return this.error(error_1.ErrorKind.INVALID_NUMBER_SKELETON, location);
|
|
716
719
|
}
|
|
717
720
|
return {
|
|
718
721
|
val: {
|
|
719
|
-
type: SKELETON_TYPE.number,
|
|
722
|
+
type: types_1.SKELETON_TYPE.number,
|
|
720
723
|
tokens: tokens,
|
|
721
724
|
location: location,
|
|
722
725
|
parsedOptions: this.shouldParseSkeletons
|
|
723
|
-
? parseNumberSkeleton(tokens)
|
|
726
|
+
? (0, icu_skeleton_parser_1.parseNumberSkeleton)(tokens)
|
|
724
727
|
: {},
|
|
725
728
|
},
|
|
726
729
|
err: null,
|
|
@@ -750,7 +753,7 @@ var Parser = /** @class */ (function () {
|
|
|
750
753
|
var startPosition = this.clonePosition();
|
|
751
754
|
if (parentArgType !== 'select' && this.bumpIf('=')) {
|
|
752
755
|
// Try parse `={number}` selector
|
|
753
|
-
var result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR);
|
|
756
|
+
var result = this.tryParseDecimalInteger(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, error_1.ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR);
|
|
754
757
|
if (result.err) {
|
|
755
758
|
return result;
|
|
756
759
|
}
|
|
@@ -764,8 +767,8 @@ var Parser = /** @class */ (function () {
|
|
|
764
767
|
// Duplicate selector clauses
|
|
765
768
|
if (parsedSelectors.has(selector)) {
|
|
766
769
|
return this.error(parentArgType === 'select'
|
|
767
|
-
? ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR
|
|
768
|
-
: ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation);
|
|
770
|
+
? error_1.ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR
|
|
771
|
+
: error_1.ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation);
|
|
769
772
|
}
|
|
770
773
|
if (selector === 'other') {
|
|
771
774
|
hasOtherClause = true;
|
|
@@ -777,8 +780,8 @@ var Parser = /** @class */ (function () {
|
|
|
777
780
|
var openingBracePosition = this.clonePosition();
|
|
778
781
|
if (!this.bumpIf('{')) {
|
|
779
782
|
return this.error(parentArgType === 'select'
|
|
780
|
-
? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT
|
|
781
|
-
: ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition()));
|
|
783
|
+
? error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT
|
|
784
|
+
: error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition()));
|
|
782
785
|
}
|
|
783
786
|
var fragmentResult = this.parseMessage(nestingLevel + 1, parentArgType, expectCloseTag);
|
|
784
787
|
if (fragmentResult.err) {
|
|
@@ -803,11 +806,11 @@ var Parser = /** @class */ (function () {
|
|
|
803
806
|
}
|
|
804
807
|
if (options.length === 0) {
|
|
805
808
|
return this.error(parentArgType === 'select'
|
|
806
|
-
? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR
|
|
807
|
-
: ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition()));
|
|
809
|
+
? error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR
|
|
810
|
+
: error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition()));
|
|
808
811
|
}
|
|
809
812
|
if (this.requiresOtherClause && !hasOtherClause) {
|
|
810
|
-
return this.error(ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition()));
|
|
813
|
+
return this.error(error_1.ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition()));
|
|
811
814
|
}
|
|
812
815
|
return { val: options, err: null };
|
|
813
816
|
};
|
|
@@ -973,7 +976,7 @@ var Parser = /** @class */ (function () {
|
|
|
973
976
|
};
|
|
974
977
|
return Parser;
|
|
975
978
|
}());
|
|
976
|
-
|
|
979
|
+
exports.Parser = Parser;
|
|
977
980
|
/**
|
|
978
981
|
* This check if codepoint is alphabet (lower & uppercase)
|
|
979
982
|
* @param codepoint
|
package/lib/printer.js
CHANGED
|
@@ -1,34 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printDateTimeSkeleton = exports.doPrintAST = exports.printAST = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var types_1 = require("./types");
|
|
6
|
+
function printAST(ast) {
|
|
4
7
|
return doPrintAST(ast, false);
|
|
5
8
|
}
|
|
6
|
-
|
|
9
|
+
exports.printAST = printAST;
|
|
10
|
+
function doPrintAST(ast, isInPlural) {
|
|
7
11
|
var printedNodes = ast.map(function (el, i) {
|
|
8
|
-
if (isLiteralElement(el)) {
|
|
12
|
+
if ((0, types_1.isLiteralElement)(el)) {
|
|
9
13
|
return printLiteralElement(el, isInPlural, i === 0, i === ast.length - 1);
|
|
10
14
|
}
|
|
11
|
-
if (isArgumentElement(el)) {
|
|
15
|
+
if ((0, types_1.isArgumentElement)(el)) {
|
|
12
16
|
return printArgumentElement(el);
|
|
13
17
|
}
|
|
14
|
-
if (isDateElement(el) || isTimeElement(el) || isNumberElement(el)) {
|
|
18
|
+
if ((0, types_1.isDateElement)(el) || (0, types_1.isTimeElement)(el) || (0, types_1.isNumberElement)(el)) {
|
|
15
19
|
return printSimpleFormatElement(el);
|
|
16
20
|
}
|
|
17
|
-
if (isPluralElement(el)) {
|
|
21
|
+
if ((0, types_1.isPluralElement)(el)) {
|
|
18
22
|
return printPluralElement(el);
|
|
19
23
|
}
|
|
20
|
-
if (isSelectElement(el)) {
|
|
24
|
+
if ((0, types_1.isSelectElement)(el)) {
|
|
21
25
|
return printSelectElement(el);
|
|
22
26
|
}
|
|
23
|
-
if (isPoundElement(el)) {
|
|
27
|
+
if ((0, types_1.isPoundElement)(el)) {
|
|
24
28
|
return '#';
|
|
25
29
|
}
|
|
26
|
-
if (isTagElement(el)) {
|
|
30
|
+
if ((0, types_1.isTagElement)(el)) {
|
|
27
31
|
return printTagElement(el);
|
|
28
32
|
}
|
|
29
33
|
});
|
|
30
34
|
return printedNodes.join('');
|
|
31
35
|
}
|
|
36
|
+
exports.doPrintAST = doPrintAST;
|
|
32
37
|
function printTagElement(el) {
|
|
33
38
|
return "<".concat(el.value, ">").concat(printAST(el.children), "</").concat(el.value, ">");
|
|
34
39
|
}
|
|
@@ -55,7 +60,7 @@ function printArgumentElement(_a) {
|
|
|
55
60
|
return "{".concat(value, "}");
|
|
56
61
|
}
|
|
57
62
|
function printSimpleFormatElement(el) {
|
|
58
|
-
return "{".concat(el.value, ", ").concat(TYPE[el.type]).concat(el.style ? ", ".concat(printArgumentStyle(el.style)) : '', "}");
|
|
63
|
+
return "{".concat(el.value, ", ").concat(types_1.TYPE[el.type]).concat(el.style ? ", ".concat(printArgumentStyle(el.style)) : '', "}");
|
|
59
64
|
}
|
|
60
65
|
function printNumberSkeletonToken(token) {
|
|
61
66
|
var stem = token.stem, options = token.options;
|
|
@@ -67,16 +72,17 @@ function printArgumentStyle(style) {
|
|
|
67
72
|
if (typeof style === 'string') {
|
|
68
73
|
return printEscapedMessage(style);
|
|
69
74
|
}
|
|
70
|
-
else if (style.type === SKELETON_TYPE.dateTime) {
|
|
75
|
+
else if (style.type === types_1.SKELETON_TYPE.dateTime) {
|
|
71
76
|
return "::".concat(printDateTimeSkeleton(style));
|
|
72
77
|
}
|
|
73
78
|
else {
|
|
74
79
|
return "::".concat(style.tokens.map(printNumberSkeletonToken).join(' '));
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
|
-
|
|
82
|
+
function printDateTimeSkeleton(style) {
|
|
78
83
|
return style.pattern;
|
|
79
84
|
}
|
|
85
|
+
exports.printDateTimeSkeleton = printDateTimeSkeleton;
|
|
80
86
|
function printSelectElement(el) {
|
|
81
87
|
var msg = [
|
|
82
88
|
el.value,
|
|
@@ -92,7 +98,7 @@ function printPluralElement(el) {
|
|
|
92
98
|
var msg = [
|
|
93
99
|
el.value,
|
|
94
100
|
type,
|
|
95
|
-
__spreadArray([
|
|
101
|
+
tslib_1.__spreadArray([
|
|
96
102
|
el.offset ? "offset:".concat(el.offset) : ''
|
|
97
103
|
], Object.keys(el.options).map(function (id) { return "".concat(id, "{").concat(doPrintAST(el.options[id].value, true), "}"); }), true).filter(Boolean)
|
|
98
104
|
.join(' '),
|
package/lib/regex.generated.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WHITE_SPACE_REGEX = exports.SPACE_SEPARATOR_REGEX = void 0;
|
|
1
4
|
// @generated from regex-gen.ts
|
|
2
|
-
|
|
3
|
-
|
|
5
|
+
exports.SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/;
|
|
6
|
+
exports.WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/;
|
package/lib/types.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNumberElement = exports.createLiteralElement = exports.isDateTimeSkeleton = exports.isNumberSkeleton = exports.isTagElement = exports.isPoundElement = exports.isPluralElement = exports.isSelectElement = exports.isTimeElement = exports.isDateElement = exports.isNumberElement = exports.isArgumentElement = exports.isLiteralElement = exports.SKELETON_TYPE = exports.TYPE = void 0;
|
|
4
|
+
var TYPE;
|
|
2
5
|
(function (TYPE) {
|
|
3
6
|
/**
|
|
4
7
|
* Raw text
|
|
@@ -37,58 +40,71 @@ export var TYPE;
|
|
|
37
40
|
* XML-like tag
|
|
38
41
|
*/
|
|
39
42
|
TYPE[TYPE["tag"] = 8] = "tag";
|
|
40
|
-
})(TYPE || (TYPE = {}));
|
|
41
|
-
|
|
43
|
+
})(TYPE || (exports.TYPE = TYPE = {}));
|
|
44
|
+
var SKELETON_TYPE;
|
|
42
45
|
(function (SKELETON_TYPE) {
|
|
43
46
|
SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
|
|
44
47
|
SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
|
|
45
|
-
})(SKELETON_TYPE || (SKELETON_TYPE = {}));
|
|
48
|
+
})(SKELETON_TYPE || (exports.SKELETON_TYPE = SKELETON_TYPE = {}));
|
|
46
49
|
/**
|
|
47
50
|
* Type Guards
|
|
48
51
|
*/
|
|
49
|
-
|
|
52
|
+
function isLiteralElement(el) {
|
|
50
53
|
return el.type === TYPE.literal;
|
|
51
54
|
}
|
|
52
|
-
|
|
55
|
+
exports.isLiteralElement = isLiteralElement;
|
|
56
|
+
function isArgumentElement(el) {
|
|
53
57
|
return el.type === TYPE.argument;
|
|
54
58
|
}
|
|
55
|
-
|
|
59
|
+
exports.isArgumentElement = isArgumentElement;
|
|
60
|
+
function isNumberElement(el) {
|
|
56
61
|
return el.type === TYPE.number;
|
|
57
62
|
}
|
|
58
|
-
|
|
63
|
+
exports.isNumberElement = isNumberElement;
|
|
64
|
+
function isDateElement(el) {
|
|
59
65
|
return el.type === TYPE.date;
|
|
60
66
|
}
|
|
61
|
-
|
|
67
|
+
exports.isDateElement = isDateElement;
|
|
68
|
+
function isTimeElement(el) {
|
|
62
69
|
return el.type === TYPE.time;
|
|
63
70
|
}
|
|
64
|
-
|
|
71
|
+
exports.isTimeElement = isTimeElement;
|
|
72
|
+
function isSelectElement(el) {
|
|
65
73
|
return el.type === TYPE.select;
|
|
66
74
|
}
|
|
67
|
-
|
|
75
|
+
exports.isSelectElement = isSelectElement;
|
|
76
|
+
function isPluralElement(el) {
|
|
68
77
|
return el.type === TYPE.plural;
|
|
69
78
|
}
|
|
70
|
-
|
|
79
|
+
exports.isPluralElement = isPluralElement;
|
|
80
|
+
function isPoundElement(el) {
|
|
71
81
|
return el.type === TYPE.pound;
|
|
72
82
|
}
|
|
73
|
-
|
|
83
|
+
exports.isPoundElement = isPoundElement;
|
|
84
|
+
function isTagElement(el) {
|
|
74
85
|
return el.type === TYPE.tag;
|
|
75
86
|
}
|
|
76
|
-
|
|
87
|
+
exports.isTagElement = isTagElement;
|
|
88
|
+
function isNumberSkeleton(el) {
|
|
77
89
|
return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.number);
|
|
78
90
|
}
|
|
79
|
-
|
|
91
|
+
exports.isNumberSkeleton = isNumberSkeleton;
|
|
92
|
+
function isDateTimeSkeleton(el) {
|
|
80
93
|
return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.dateTime);
|
|
81
94
|
}
|
|
82
|
-
|
|
95
|
+
exports.isDateTimeSkeleton = isDateTimeSkeleton;
|
|
96
|
+
function createLiteralElement(value) {
|
|
83
97
|
return {
|
|
84
98
|
type: TYPE.literal,
|
|
85
99
|
value: value,
|
|
86
100
|
};
|
|
87
101
|
}
|
|
88
|
-
|
|
102
|
+
exports.createLiteralElement = createLiteralElement;
|
|
103
|
+
function createNumberElement(value, style) {
|
|
89
104
|
return {
|
|
90
105
|
type: TYPE.number,
|
|
91
106
|
value: value,
|
|
92
107
|
style: style,
|
|
93
108
|
};
|
|
94
109
|
}
|
|
110
|
+
exports.createNumberElement = createNumberElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/icu-messageformat-parser",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"tslib": "^2.4.0",
|
|
15
|
-
"@formatjs/ecma402-abstract": "1.17.
|
|
16
|
-
"@formatjs/icu-skeleton-parser": "1.6.
|
|
15
|
+
"@formatjs/ecma402-abstract": "1.17.4",
|
|
16
|
+
"@formatjs/icu-skeleton-parser": "1.6.4"
|
|
17
17
|
}
|
|
18
18
|
}
|
package/types.js
CHANGED
|
@@ -40,12 +40,12 @@ var TYPE;
|
|
|
40
40
|
* XML-like tag
|
|
41
41
|
*/
|
|
42
42
|
TYPE[TYPE["tag"] = 8] = "tag";
|
|
43
|
-
})(TYPE
|
|
43
|
+
})(TYPE || (exports.TYPE = TYPE = {}));
|
|
44
44
|
var SKELETON_TYPE;
|
|
45
45
|
(function (SKELETON_TYPE) {
|
|
46
46
|
SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
|
|
47
47
|
SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
|
|
48
|
-
})(SKELETON_TYPE
|
|
48
|
+
})(SKELETON_TYPE || (exports.SKELETON_TYPE = SKELETON_TYPE = {}));
|
|
49
49
|
/**
|
|
50
50
|
* Type Guards
|
|
51
51
|
*/
|