@formatjs/icu-messageformat-parser 3.2.1 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/date-time-pattern-generator.d.ts +6 -6
- package/date-time-pattern-generator.js +62 -77
- package/error.d.ts +64 -64
- package/error.js +64 -63
- package/index.d.ts +4 -4
- package/index.js +40 -42
- package/manipulator.d.ts +19 -19
- package/manipulator.js +158 -159
- package/no-parser.d.ts +2 -2
- package/no-parser.js +4 -4
- package/package.json +4 -4
- package/parser.d.ts +142 -139
- package/parser.js +839 -900
- package/printer.d.ts +1 -1
- package/printer.js +68 -79
- package/regex.generated.js +2 -2
- package/time-data.generated.js +1162 -1424
- package/types.d.ts +77 -74
- package/types.js +68 -67
package/printer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateTimeSkeleton, MessageFormatElement } from
|
|
1
|
+
import { type DateTimeSkeleton, type MessageFormatElement } from "./types.js";
|
|
2
2
|
export declare function printAST(ast: MessageFormatElement[]): string;
|
|
3
3
|
export declare function doPrintAST(ast: MessageFormatElement[], isInPlural: boolean): string;
|
|
4
4
|
export declare function printDateTimeSkeleton(style: DateTimeSkeleton): string;
|
package/printer.js
CHANGED
|
@@ -1,101 +1,90 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isPluralElement, isPoundElement, isSelectElement, isTagElement, isTimeElement, SKELETON_TYPE, TYPE
|
|
1
|
+
import "@formatjs/icu-skeleton-parser";
|
|
2
|
+
import { isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isPluralElement, isPoundElement, isSelectElement, isTagElement, isTimeElement, SKELETON_TYPE, TYPE } from "./types.js";
|
|
3
3
|
export function printAST(ast) {
|
|
4
|
-
|
|
4
|
+
return doPrintAST(ast, false);
|
|
5
5
|
}
|
|
6
6
|
export function doPrintAST(ast, isInPlural) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
7
|
+
const printedNodes = ast.map((el, i) => {
|
|
8
|
+
if (isLiteralElement(el)) {
|
|
9
|
+
return printLiteralElement(el, isInPlural, i === 0, i === ast.length - 1);
|
|
10
|
+
}
|
|
11
|
+
if (isArgumentElement(el)) {
|
|
12
|
+
return printArgumentElement(el);
|
|
13
|
+
}
|
|
14
|
+
if (isDateElement(el) || isTimeElement(el) || isNumberElement(el)) {
|
|
15
|
+
return printSimpleFormatElement(el);
|
|
16
|
+
}
|
|
17
|
+
if (isPluralElement(el)) {
|
|
18
|
+
return printPluralElement(el);
|
|
19
|
+
}
|
|
20
|
+
if (isSelectElement(el)) {
|
|
21
|
+
return printSelectElement(el);
|
|
22
|
+
}
|
|
23
|
+
if (isPoundElement(el)) {
|
|
24
|
+
return "#";
|
|
25
|
+
}
|
|
26
|
+
if (isTagElement(el)) {
|
|
27
|
+
return printTagElement(el);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return printedNodes.join("");
|
|
31
31
|
}
|
|
32
32
|
function printTagElement(el) {
|
|
33
|
-
|
|
33
|
+
return `<${el.value}>${printAST(el.children)}</${el.value}>`;
|
|
34
34
|
}
|
|
35
35
|
function printEscapedMessage(message) {
|
|
36
|
-
|
|
36
|
+
return message.replace(/([{}](?:[\s\S]*[{}])?)/, `'$1'`);
|
|
37
37
|
}
|
|
38
|
-
function printLiteralElement(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return isInPlural ? escaped.replace('#', "'#'") : escaped;
|
|
38
|
+
function printLiteralElement({ value }, isInPlural, isFirstEl, isLastEl) {
|
|
39
|
+
let escaped = value;
|
|
40
|
+
// If this literal starts with a ' and its not the 1st node, this means the node before it is non-literal
|
|
41
|
+
// and the `'` needs to be unescaped
|
|
42
|
+
if (!isFirstEl && escaped[0] === `'`) {
|
|
43
|
+
escaped = `''${escaped.slice(1)}`;
|
|
44
|
+
}
|
|
45
|
+
// Same logic but for last el
|
|
46
|
+
if (!isLastEl && escaped[escaped.length - 1] === `'`) {
|
|
47
|
+
escaped = `${escaped.slice(0, escaped.length - 1)}''`;
|
|
48
|
+
}
|
|
49
|
+
escaped = printEscapedMessage(escaped);
|
|
50
|
+
return isInPlural ? escaped.replace("#", "'#'") : escaped;
|
|
52
51
|
}
|
|
53
|
-
function printArgumentElement(
|
|
54
|
-
|
|
55
|
-
return "{".concat(value, "}");
|
|
52
|
+
function printArgumentElement({ value }) {
|
|
53
|
+
return `{${value}}`;
|
|
56
54
|
}
|
|
57
55
|
function printSimpleFormatElement(el) {
|
|
58
|
-
|
|
56
|
+
return `{${el.value}, ${TYPE[el.type]}${el.style ? `, ${printArgumentStyle(el.style)}` : ""}}`;
|
|
59
57
|
}
|
|
60
58
|
function printNumberSkeletonToken(token) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
? stem
|
|
64
|
-
: "".concat(stem).concat(options.map(function (o) { return "/".concat(o); }).join(''));
|
|
59
|
+
const { stem, options } = token;
|
|
60
|
+
return options.length === 0 ? stem : `${stem}${options.map((o) => `/${o}`).join("")}`;
|
|
65
61
|
}
|
|
66
62
|
function printArgumentStyle(style) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return "::".concat(style.tokens.map(printNumberSkeletonToken).join(' '));
|
|
75
|
-
}
|
|
63
|
+
if (typeof style === "string") {
|
|
64
|
+
return printEscapedMessage(style);
|
|
65
|
+
} else if (style.type === SKELETON_TYPE.dateTime) {
|
|
66
|
+
return `::${printDateTimeSkeleton(style)}`;
|
|
67
|
+
} else {
|
|
68
|
+
return `::${style.tokens.map(printNumberSkeletonToken).join(" ")}`;
|
|
69
|
+
}
|
|
76
70
|
}
|
|
77
71
|
export function printDateTimeSkeleton(style) {
|
|
78
|
-
|
|
72
|
+
return style.pattern;
|
|
79
73
|
}
|
|
80
74
|
function printSelectElement(el) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
].join(',');
|
|
88
|
-
return "{".concat(msg, "}");
|
|
75
|
+
const msg = [
|
|
76
|
+
el.value,
|
|
77
|
+
"select",
|
|
78
|
+
Object.keys(el.options).map((id) => `${id}{${doPrintAST(el.options[id].value, false)}}`).join(" ")
|
|
79
|
+
].join(",");
|
|
80
|
+
return `{${msg}}`;
|
|
89
81
|
}
|
|
90
82
|
function printPluralElement(el) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
.join(' '),
|
|
99
|
-
].join(',');
|
|
100
|
-
return "{".concat(msg, "}");
|
|
83
|
+
const type = el.pluralType === "cardinal" ? "plural" : "selectordinal";
|
|
84
|
+
const msg = [
|
|
85
|
+
el.value,
|
|
86
|
+
type,
|
|
87
|
+
[el.offset ? `offset:${el.offset}` : "", ...Object.keys(el.options).map((id) => `${id}{${doPrintAST(el.options[id].value, true)}}`)].filter(Boolean).join(" ")
|
|
88
|
+
].join(",");
|
|
89
|
+
return `{${msg}}`;
|
|
101
90
|
}
|
package/regex.generated.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @generated from regex-gen.ts
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export const SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/;
|
|
3
|
+
export const WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/;
|