@formatjs/icu-messageformat-parser 2.11.4 → 3.0.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/date-time-pattern-generator.js +6 -9
- package/error.d.ts +1 -1
- package/error.js +2 -5
- package/index.d.ts +4 -4
- package/index.js +16 -21
- package/manipulator.d.ts +1 -1
- package/manipulator.js +16 -20
- package/no-parser.d.ts +2 -2
- package/no-parser.js +4 -10
- package/package.json +10 -5
- package/parser.d.ts +2 -2
- package/parser.js +59 -62
- package/printer.d.ts +1 -1
- package/printer.js +15 -20
- package/regex.generated.js +2 -5
- package/time-data.generated.js +1 -4
- package/types.js +17 -33
- package/lib/date-time-pattern-generator.d.ts +0 -8
- package/lib/date-time-pattern-generator.js +0 -83
- package/lib/error.d.ts +0 -68
- package/lib/error.js +0 -63
- package/lib/index.d.ts +0 -7
- package/lib/index.js +0 -46
- package/lib/manipulator.d.ts +0 -26
- package/lib/manipulator.js +0 -135
- package/lib/no-parser.d.ts +0 -4
- package/lib/no-parser.js +0 -6
- package/lib/parser.d.ts +0 -147
- package/lib/parser.js +0 -1276
- package/lib/printer.d.ts +0 -4
- package/lib/printer.js +0 -101
- package/lib/regex.generated.d.ts +0 -2
- package/lib/regex.generated.js +0 -3
- package/lib/time-data.generated.d.ts +0 -1
- package/lib/time-data.generated.js +0 -1417
- package/lib/types.d.ts +0 -120
- package/lib/types.js +0 -94
package/lib/printer.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { DateTimeSkeleton, MessageFormatElement } from './types';
|
|
2
|
-
export declare function printAST(ast: MessageFormatElement[]): string;
|
|
3
|
-
export declare function doPrintAST(ast: MessageFormatElement[], isInPlural: boolean): string;
|
|
4
|
-
export declare function printDateTimeSkeleton(style: DateTimeSkeleton): string;
|
package/lib/printer.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { __spreadArray } from "tslib";
|
|
2
|
-
import { isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isPluralElement, isPoundElement, isSelectElement, isTagElement, isTimeElement, SKELETON_TYPE, TYPE, } from './types';
|
|
3
|
-
export function printAST(ast) {
|
|
4
|
-
return doPrintAST(ast, false);
|
|
5
|
-
}
|
|
6
|
-
export function doPrintAST(ast, isInPlural) {
|
|
7
|
-
var printedNodes = ast.map(function (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
|
-
}
|
|
32
|
-
function printTagElement(el) {
|
|
33
|
-
return "<".concat(el.value, ">").concat(printAST(el.children), "</").concat(el.value, ">");
|
|
34
|
-
}
|
|
35
|
-
function printEscapedMessage(message) {
|
|
36
|
-
return message.replace(/([{}](?:[\s\S]*[{}])?)/, "'$1'");
|
|
37
|
-
}
|
|
38
|
-
function printLiteralElement(_a, isInPlural, isFirstEl, isLastEl) {
|
|
39
|
-
var value = _a.value;
|
|
40
|
-
var escaped = value;
|
|
41
|
-
// If this literal starts with a ' and its not the 1st node, this means the node before it is non-literal
|
|
42
|
-
// and the `'` needs to be unescaped
|
|
43
|
-
if (!isFirstEl && escaped[0] === "'") {
|
|
44
|
-
escaped = "''".concat(escaped.slice(1));
|
|
45
|
-
}
|
|
46
|
-
// Same logic but for last el
|
|
47
|
-
if (!isLastEl && escaped[escaped.length - 1] === "'") {
|
|
48
|
-
escaped = "".concat(escaped.slice(0, escaped.length - 1), "''");
|
|
49
|
-
}
|
|
50
|
-
escaped = printEscapedMessage(escaped);
|
|
51
|
-
return isInPlural ? escaped.replace('#', "'#'") : escaped;
|
|
52
|
-
}
|
|
53
|
-
function printArgumentElement(_a) {
|
|
54
|
-
var value = _a.value;
|
|
55
|
-
return "{".concat(value, "}");
|
|
56
|
-
}
|
|
57
|
-
function printSimpleFormatElement(el) {
|
|
58
|
-
return "{".concat(el.value, ", ").concat(TYPE[el.type]).concat(el.style ? ", ".concat(printArgumentStyle(el.style)) : '', "}");
|
|
59
|
-
}
|
|
60
|
-
function printNumberSkeletonToken(token) {
|
|
61
|
-
var stem = token.stem, options = token.options;
|
|
62
|
-
return options.length === 0
|
|
63
|
-
? stem
|
|
64
|
-
: "".concat(stem).concat(options.map(function (o) { return "/".concat(o); }).join(''));
|
|
65
|
-
}
|
|
66
|
-
function printArgumentStyle(style) {
|
|
67
|
-
if (typeof style === 'string') {
|
|
68
|
-
return printEscapedMessage(style);
|
|
69
|
-
}
|
|
70
|
-
else if (style.type === SKELETON_TYPE.dateTime) {
|
|
71
|
-
return "::".concat(printDateTimeSkeleton(style));
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
return "::".concat(style.tokens.map(printNumberSkeletonToken).join(' '));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export function printDateTimeSkeleton(style) {
|
|
78
|
-
return style.pattern;
|
|
79
|
-
}
|
|
80
|
-
function printSelectElement(el) {
|
|
81
|
-
var msg = [
|
|
82
|
-
el.value,
|
|
83
|
-
'select',
|
|
84
|
-
Object.keys(el.options)
|
|
85
|
-
.map(function (id) { return "".concat(id, "{").concat(doPrintAST(el.options[id].value, false), "}"); })
|
|
86
|
-
.join(' '),
|
|
87
|
-
].join(',');
|
|
88
|
-
return "{".concat(msg, "}");
|
|
89
|
-
}
|
|
90
|
-
function printPluralElement(el) {
|
|
91
|
-
var type = el.pluralType === 'cardinal' ? 'plural' : 'selectordinal';
|
|
92
|
-
var msg = [
|
|
93
|
-
el.value,
|
|
94
|
-
type,
|
|
95
|
-
__spreadArray([
|
|
96
|
-
el.offset ? "offset:".concat(el.offset) : ''
|
|
97
|
-
], Object.keys(el.options).map(function (id) { return "".concat(id, "{").concat(doPrintAST(el.options[id].value, true), "}"); }), true).filter(Boolean)
|
|
98
|
-
.join(' '),
|
|
99
|
-
].join(',');
|
|
100
|
-
return "{".concat(msg, "}");
|
|
101
|
-
}
|
package/lib/regex.generated.d.ts
DELETED
package/lib/regex.generated.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const timeData: Record<string, string[]>;
|