@formatjs/icu-messageformat-parser 2.0.12
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 +25 -0
- package/error.d.ts +69 -0
- package/error.d.ts.map +1 -0
- package/error.js +66 -0
- package/index.d.ts +5 -0
- package/index.d.ts.map +1 -0
- package/index.js +47 -0
- package/lib/error.d.ts +69 -0
- package/lib/error.d.ts.map +1 -0
- package/lib/error.js +63 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +43 -0
- package/lib/manipulator.d.ts +14 -0
- package/lib/manipulator.d.ts.map +1 -0
- package/lib/manipulator.js +52 -0
- package/lib/no-parser.d.ts +3 -0
- package/lib/no-parser.d.ts.map +1 -0
- package/lib/no-parser.js +4 -0
- package/lib/parser.d.ts +143 -0
- package/lib/parser.d.ts.map +1 -0
- package/lib/parser.js +1267 -0
- package/lib/printer.d.ts +5 -0
- package/lib/printer.d.ts.map +1 -0
- package/lib/printer.js +91 -0
- package/lib/regex.generated.d.ts +3 -0
- package/lib/regex.generated.d.ts.map +1 -0
- package/lib/regex.generated.js +3 -0
- package/lib/types.d.ts +129 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +94 -0
- package/manipulator.d.ts +14 -0
- package/manipulator.d.ts.map +1 -0
- package/manipulator.js +56 -0
- package/no-parser.d.ts +3 -0
- package/no-parser.d.ts.map +1 -0
- package/no-parser.js +9 -0
- package/package.json +13 -0
- package/parser.d.ts +143 -0
- package/parser.d.ts.map +1 -0
- package/parser.js +1270 -0
- package/printer.d.ts +5 -0
- package/printer.d.ts.map +1 -0
- package/printer.js +97 -0
- package/regex.generated.d.ts +3 -0
- package/regex.generated.d.ts.map +1 -0
- package/regex.generated.js +6 -0
- package/types.d.ts +129 -0
- package/types.d.ts.map +1 -0
- package/types.js +110 -0
package/printer.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MessageFormatElement, DateTimeSkeleton } 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;
|
|
5
|
+
//# sourceMappingURL=printer.d.ts.map
|
package/printer.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../../../../packages/icu-messageformat-parser/printer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EAoBpB,gBAAgB,EAEjB,MAAM,SAAS,CAAA;AAEhB,wBAAgB,QAAQ,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAE5D;AAED,wBAAgB,UAAU,CACxB,GAAG,EAAE,oBAAoB,EAAE,EAC3B,UAAU,EAAE,OAAO,GAClB,MAAM,CA8BR;AA4CD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAErE"}
|
package/printer.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
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) {
|
|
7
|
+
return doPrintAST(ast, false);
|
|
8
|
+
}
|
|
9
|
+
exports.printAST = printAST;
|
|
10
|
+
function doPrintAST(ast, isInPlural) {
|
|
11
|
+
var printedNodes = ast.map(function (el) {
|
|
12
|
+
if (types_1.isLiteralElement(el)) {
|
|
13
|
+
return printLiteralElement(el, isInPlural);
|
|
14
|
+
}
|
|
15
|
+
if (types_1.isArgumentElement(el)) {
|
|
16
|
+
return printArgumentElement(el);
|
|
17
|
+
}
|
|
18
|
+
if (types_1.isDateElement(el) || types_1.isTimeElement(el) || types_1.isNumberElement(el)) {
|
|
19
|
+
return printSimpleFormatElement(el);
|
|
20
|
+
}
|
|
21
|
+
if (types_1.isPluralElement(el)) {
|
|
22
|
+
return printPluralElement(el);
|
|
23
|
+
}
|
|
24
|
+
if (types_1.isSelectElement(el)) {
|
|
25
|
+
return printSelectElement(el);
|
|
26
|
+
}
|
|
27
|
+
if (types_1.isPoundElement(el)) {
|
|
28
|
+
return '#';
|
|
29
|
+
}
|
|
30
|
+
if (types_1.isTagElement(el)) {
|
|
31
|
+
return printTagElement(el);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return printedNodes.join('');
|
|
35
|
+
}
|
|
36
|
+
exports.doPrintAST = doPrintAST;
|
|
37
|
+
function printTagElement(el) {
|
|
38
|
+
return "<" + el.value + ">" + printAST(el.children) + "</" + el.value + ">";
|
|
39
|
+
}
|
|
40
|
+
function printEscapedMessage(message) {
|
|
41
|
+
return message.replace(/([{}](?:.*[{}])?)/su, "'$1'");
|
|
42
|
+
}
|
|
43
|
+
function printLiteralElement(_a, isInPlural) {
|
|
44
|
+
var value = _a.value;
|
|
45
|
+
var escaped = printEscapedMessage(value);
|
|
46
|
+
return isInPlural ? escaped.replace('#', "'#'") : escaped;
|
|
47
|
+
}
|
|
48
|
+
function printArgumentElement(_a) {
|
|
49
|
+
var value = _a.value;
|
|
50
|
+
return "{" + value + "}";
|
|
51
|
+
}
|
|
52
|
+
function printSimpleFormatElement(el) {
|
|
53
|
+
return "{" + el.value + ", " + types_1.TYPE[el.type] + (el.style ? ", " + printArgumentStyle(el.style) : '') + "}";
|
|
54
|
+
}
|
|
55
|
+
function printNumberSkeletonToken(token) {
|
|
56
|
+
var stem = token.stem, options = token.options;
|
|
57
|
+
return options.length === 0
|
|
58
|
+
? stem
|
|
59
|
+
: "" + stem + options.map(function (o) { return "/" + o; }).join('');
|
|
60
|
+
}
|
|
61
|
+
function printArgumentStyle(style) {
|
|
62
|
+
if (typeof style === 'string') {
|
|
63
|
+
return printEscapedMessage(style);
|
|
64
|
+
}
|
|
65
|
+
else if (style.type === types_1.SKELETON_TYPE.dateTime) {
|
|
66
|
+
return "::" + printDateTimeSkeleton(style);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return "::" + style.tokens.map(printNumberSkeletonToken).join(' ');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function printDateTimeSkeleton(style) {
|
|
73
|
+
return style.pattern;
|
|
74
|
+
}
|
|
75
|
+
exports.printDateTimeSkeleton = printDateTimeSkeleton;
|
|
76
|
+
function printSelectElement(el) {
|
|
77
|
+
var msg = [
|
|
78
|
+
el.value,
|
|
79
|
+
'select',
|
|
80
|
+
Object.keys(el.options)
|
|
81
|
+
.map(function (id) { return id + "{" + doPrintAST(el.options[id].value, false) + "}"; })
|
|
82
|
+
.join(' '),
|
|
83
|
+
].join(',');
|
|
84
|
+
return "{" + msg + "}";
|
|
85
|
+
}
|
|
86
|
+
function printPluralElement(el) {
|
|
87
|
+
var type = el.pluralType === 'cardinal' ? 'plural' : 'selectordinal';
|
|
88
|
+
var msg = [
|
|
89
|
+
el.value,
|
|
90
|
+
type,
|
|
91
|
+
tslib_1.__spreadArray([
|
|
92
|
+
el.offset ? "offset:" + el.offset : ''
|
|
93
|
+
], Object.keys(el.options).map(function (id) { return id + "{" + doPrintAST(el.options[id].value, true) + "}"; })).filter(Boolean)
|
|
94
|
+
.join(' '),
|
|
95
|
+
].join(',');
|
|
96
|
+
return "{" + msg + "}";
|
|
97
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex.generated.d.ts","sourceRoot":"","sources":["../../../../../packages/icu-messageformat-parser/regex.generated.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,qBAAqB,QAAiD,CAAA;AACnF,eAAO,MAAM,iBAAiB,QAAyC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WHITE_SPACE_REGEX = exports.SPACE_SEPARATOR_REGEX = void 0;
|
|
4
|
+
// @generated from regex-gen.ts
|
|
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/types.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { NumberFormatOptions } from '@formatjs/ecma402-abstract';
|
|
2
|
+
import { NumberSkeletonToken } from '@formatjs/icu-skeleton-parser';
|
|
3
|
+
export interface ExtendedNumberFormatOptions extends NumberFormatOptions {
|
|
4
|
+
scale?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare enum TYPE {
|
|
7
|
+
/**
|
|
8
|
+
* Raw text
|
|
9
|
+
*/
|
|
10
|
+
literal = 0,
|
|
11
|
+
/**
|
|
12
|
+
* Variable w/o any format, e.g `var` in `this is a {var}`
|
|
13
|
+
*/
|
|
14
|
+
argument = 1,
|
|
15
|
+
/**
|
|
16
|
+
* Variable w/ number format
|
|
17
|
+
*/
|
|
18
|
+
number = 2,
|
|
19
|
+
/**
|
|
20
|
+
* Variable w/ date format
|
|
21
|
+
*/
|
|
22
|
+
date = 3,
|
|
23
|
+
/**
|
|
24
|
+
* Variable w/ time format
|
|
25
|
+
*/
|
|
26
|
+
time = 4,
|
|
27
|
+
/**
|
|
28
|
+
* Variable w/ select format
|
|
29
|
+
*/
|
|
30
|
+
select = 5,
|
|
31
|
+
/**
|
|
32
|
+
* Variable w/ plural format
|
|
33
|
+
*/
|
|
34
|
+
plural = 6,
|
|
35
|
+
/**
|
|
36
|
+
* Only possible within plural argument.
|
|
37
|
+
* This is the `#` symbol that will be substituted with the count.
|
|
38
|
+
*/
|
|
39
|
+
pound = 7,
|
|
40
|
+
/**
|
|
41
|
+
* XML-like tag
|
|
42
|
+
*/
|
|
43
|
+
tag = 8
|
|
44
|
+
}
|
|
45
|
+
export declare enum SKELETON_TYPE {
|
|
46
|
+
number = 0,
|
|
47
|
+
dateTime = 1
|
|
48
|
+
}
|
|
49
|
+
export interface LocationDetails {
|
|
50
|
+
offset: number;
|
|
51
|
+
line: number;
|
|
52
|
+
column: number;
|
|
53
|
+
}
|
|
54
|
+
export interface Location {
|
|
55
|
+
start: LocationDetails;
|
|
56
|
+
end: LocationDetails;
|
|
57
|
+
}
|
|
58
|
+
export interface BaseElement<T extends TYPE> {
|
|
59
|
+
type: T;
|
|
60
|
+
value: string;
|
|
61
|
+
location?: Location;
|
|
62
|
+
}
|
|
63
|
+
export declare type LiteralElement = BaseElement<TYPE.literal>;
|
|
64
|
+
export declare type ArgumentElement = BaseElement<TYPE.argument>;
|
|
65
|
+
export interface TagElement {
|
|
66
|
+
type: TYPE.tag;
|
|
67
|
+
value: string;
|
|
68
|
+
children: MessageFormatElement[];
|
|
69
|
+
location?: Location;
|
|
70
|
+
}
|
|
71
|
+
export interface SimpleFormatElement<T extends TYPE, S extends Skeleton> extends BaseElement<T> {
|
|
72
|
+
style?: string | S | null;
|
|
73
|
+
}
|
|
74
|
+
export declare type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>;
|
|
75
|
+
export declare type DateElement = SimpleFormatElement<TYPE.date, DateTimeSkeleton>;
|
|
76
|
+
export declare type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>;
|
|
77
|
+
export interface SelectOption {
|
|
78
|
+
id: string;
|
|
79
|
+
value: MessageFormatElement[];
|
|
80
|
+
location?: Location;
|
|
81
|
+
}
|
|
82
|
+
export declare type ValidPluralRule = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other' | string;
|
|
83
|
+
export interface PluralOrSelectOption {
|
|
84
|
+
value: MessageFormatElement[];
|
|
85
|
+
location?: Location;
|
|
86
|
+
}
|
|
87
|
+
export interface SelectElement extends BaseElement<TYPE.select> {
|
|
88
|
+
options: Record<string, PluralOrSelectOption>;
|
|
89
|
+
}
|
|
90
|
+
export interface PluralElement extends BaseElement<TYPE.plural> {
|
|
91
|
+
options: Record<ValidPluralRule, PluralOrSelectOption>;
|
|
92
|
+
offset: number;
|
|
93
|
+
pluralType: Intl.PluralRulesOptions['type'];
|
|
94
|
+
}
|
|
95
|
+
export interface PoundElement {
|
|
96
|
+
type: TYPE.pound;
|
|
97
|
+
location?: Location;
|
|
98
|
+
}
|
|
99
|
+
export declare type MessageFormatElement = ArgumentElement | DateElement | LiteralElement | NumberElement | PluralElement | PoundElement | SelectElement | TagElement | TimeElement;
|
|
100
|
+
export interface NumberSkeleton {
|
|
101
|
+
type: SKELETON_TYPE.number;
|
|
102
|
+
tokens: NumberSkeletonToken[];
|
|
103
|
+
location?: Location;
|
|
104
|
+
parsedOptions: ExtendedNumberFormatOptions;
|
|
105
|
+
}
|
|
106
|
+
export interface DateTimeSkeleton {
|
|
107
|
+
type: SKELETON_TYPE.dateTime;
|
|
108
|
+
pattern: string;
|
|
109
|
+
location?: Location;
|
|
110
|
+
parsedOptions: Intl.DateTimeFormatOptions;
|
|
111
|
+
}
|
|
112
|
+
export declare type Skeleton = NumberSkeleton | DateTimeSkeleton;
|
|
113
|
+
/**
|
|
114
|
+
* Type Guards
|
|
115
|
+
*/
|
|
116
|
+
export declare function isLiteralElement(el: MessageFormatElement): el is LiteralElement;
|
|
117
|
+
export declare function isArgumentElement(el: MessageFormatElement): el is ArgumentElement;
|
|
118
|
+
export declare function isNumberElement(el: MessageFormatElement): el is NumberElement;
|
|
119
|
+
export declare function isDateElement(el: MessageFormatElement): el is DateElement;
|
|
120
|
+
export declare function isTimeElement(el: MessageFormatElement): el is TimeElement;
|
|
121
|
+
export declare function isSelectElement(el: MessageFormatElement): el is SelectElement;
|
|
122
|
+
export declare function isPluralElement(el: MessageFormatElement): el is PluralElement;
|
|
123
|
+
export declare function isPoundElement(el: MessageFormatElement): el is PoundElement;
|
|
124
|
+
export declare function isTagElement(el: MessageFormatElement): el is TagElement;
|
|
125
|
+
export declare function isNumberSkeleton(el: NumberElement['style'] | Skeleton): el is NumberSkeleton;
|
|
126
|
+
export declare function isDateTimeSkeleton(el?: DateElement['style'] | TimeElement['style'] | Skeleton): el is DateTimeSkeleton;
|
|
127
|
+
export declare function createLiteralElement(value: string): LiteralElement;
|
|
128
|
+
export declare function createNumberElement(value: string, style?: string | null): NumberElement;
|
|
129
|
+
//# sourceMappingURL=types.d.ts.map
|
package/types.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../packages/icu-messageformat-parser/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAA;AAEjE,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB;IACtE,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,oBAAY,IAAI;IACd;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,MAAM,IAAA;IACN;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,MAAM,IAAA;IACN;;OAEG;IACH,MAAM,IAAA;IACN;;;OAGG;IACH,KAAK,IAAA;IACL;;OAEG;IACH,GAAG,IAAA;CACJ;AAED,oBAAY,aAAa;IACvB,MAAM,IAAA;IACN,QAAQ,IAAA;CACT;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AACD,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,eAAe,CAAA;IACtB,GAAG,EAAE,eAAe,CAAA;CACrB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,IAAI;IACzC,IAAI,EAAE,CAAC,CAAA;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aAAa,CAAC,EAAE,EAAE,oBAAoB,GAAG,EAAE,IAAI,WAAW,CAEzE;AACD,wBAAgB,aAAa,CAAC,EAAE,EAAE,oBAAoB,GAAG,EAAE,IAAI,WAAW,CAEzE;AACD,wBAAgB,eAAe,CAAC,EAAE,EAAE,oBAAoB,GAAG,EAAE,IAAI,aAAa,CAE7E;AACD,wBAAgB,eAAe,CAAC,EAAE,EAAE,oBAAoB,GAAG,EAAE,IAAI,aAAa,CAE7E;AACD,wBAAgB,cAAc,CAAC,EAAE,EAAE,oBAAoB,GAAG,EAAE,IAAI,YAAY,CAE3E;AACD,wBAAgB,YAAY,CAAC,EAAE,EAAE,oBAAoB,GAAG,EAAE,IAAI,UAAU,CAEvE;AACD,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,GACpC,EAAE,IAAI,cAAc,CAEtB;AACD,wBAAgB,kBAAkB,CAChC,EAAE,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,QAAQ,GAC1D,EAAE,IAAI,gBAAgB,CAExB;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAKlE;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,aAAa,CAMf"}
|
package/types.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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;
|
|
5
|
+
(function (TYPE) {
|
|
6
|
+
/**
|
|
7
|
+
* Raw text
|
|
8
|
+
*/
|
|
9
|
+
TYPE[TYPE["literal"] = 0] = "literal";
|
|
10
|
+
/**
|
|
11
|
+
* Variable w/o any format, e.g `var` in `this is a {var}`
|
|
12
|
+
*/
|
|
13
|
+
TYPE[TYPE["argument"] = 1] = "argument";
|
|
14
|
+
/**
|
|
15
|
+
* Variable w/ number format
|
|
16
|
+
*/
|
|
17
|
+
TYPE[TYPE["number"] = 2] = "number";
|
|
18
|
+
/**
|
|
19
|
+
* Variable w/ date format
|
|
20
|
+
*/
|
|
21
|
+
TYPE[TYPE["date"] = 3] = "date";
|
|
22
|
+
/**
|
|
23
|
+
* Variable w/ time format
|
|
24
|
+
*/
|
|
25
|
+
TYPE[TYPE["time"] = 4] = "time";
|
|
26
|
+
/**
|
|
27
|
+
* Variable w/ select format
|
|
28
|
+
*/
|
|
29
|
+
TYPE[TYPE["select"] = 5] = "select";
|
|
30
|
+
/**
|
|
31
|
+
* Variable w/ plural format
|
|
32
|
+
*/
|
|
33
|
+
TYPE[TYPE["plural"] = 6] = "plural";
|
|
34
|
+
/**
|
|
35
|
+
* Only possible within plural argument.
|
|
36
|
+
* This is the `#` symbol that will be substituted with the count.
|
|
37
|
+
*/
|
|
38
|
+
TYPE[TYPE["pound"] = 7] = "pound";
|
|
39
|
+
/**
|
|
40
|
+
* XML-like tag
|
|
41
|
+
*/
|
|
42
|
+
TYPE[TYPE["tag"] = 8] = "tag";
|
|
43
|
+
})(TYPE = exports.TYPE || (exports.TYPE = {}));
|
|
44
|
+
var SKELETON_TYPE;
|
|
45
|
+
(function (SKELETON_TYPE) {
|
|
46
|
+
SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
|
|
47
|
+
SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
|
|
48
|
+
})(SKELETON_TYPE = exports.SKELETON_TYPE || (exports.SKELETON_TYPE = {}));
|
|
49
|
+
/**
|
|
50
|
+
* Type Guards
|
|
51
|
+
*/
|
|
52
|
+
function isLiteralElement(el) {
|
|
53
|
+
return el.type === TYPE.literal;
|
|
54
|
+
}
|
|
55
|
+
exports.isLiteralElement = isLiteralElement;
|
|
56
|
+
function isArgumentElement(el) {
|
|
57
|
+
return el.type === TYPE.argument;
|
|
58
|
+
}
|
|
59
|
+
exports.isArgumentElement = isArgumentElement;
|
|
60
|
+
function isNumberElement(el) {
|
|
61
|
+
return el.type === TYPE.number;
|
|
62
|
+
}
|
|
63
|
+
exports.isNumberElement = isNumberElement;
|
|
64
|
+
function isDateElement(el) {
|
|
65
|
+
return el.type === TYPE.date;
|
|
66
|
+
}
|
|
67
|
+
exports.isDateElement = isDateElement;
|
|
68
|
+
function isTimeElement(el) {
|
|
69
|
+
return el.type === TYPE.time;
|
|
70
|
+
}
|
|
71
|
+
exports.isTimeElement = isTimeElement;
|
|
72
|
+
function isSelectElement(el) {
|
|
73
|
+
return el.type === TYPE.select;
|
|
74
|
+
}
|
|
75
|
+
exports.isSelectElement = isSelectElement;
|
|
76
|
+
function isPluralElement(el) {
|
|
77
|
+
return el.type === TYPE.plural;
|
|
78
|
+
}
|
|
79
|
+
exports.isPluralElement = isPluralElement;
|
|
80
|
+
function isPoundElement(el) {
|
|
81
|
+
return el.type === TYPE.pound;
|
|
82
|
+
}
|
|
83
|
+
exports.isPoundElement = isPoundElement;
|
|
84
|
+
function isTagElement(el) {
|
|
85
|
+
return el.type === TYPE.tag;
|
|
86
|
+
}
|
|
87
|
+
exports.isTagElement = isTagElement;
|
|
88
|
+
function isNumberSkeleton(el) {
|
|
89
|
+
return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.number);
|
|
90
|
+
}
|
|
91
|
+
exports.isNumberSkeleton = isNumberSkeleton;
|
|
92
|
+
function isDateTimeSkeleton(el) {
|
|
93
|
+
return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.dateTime);
|
|
94
|
+
}
|
|
95
|
+
exports.isDateTimeSkeleton = isDateTimeSkeleton;
|
|
96
|
+
function createLiteralElement(value) {
|
|
97
|
+
return {
|
|
98
|
+
type: TYPE.literal,
|
|
99
|
+
value: value,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
exports.createLiteralElement = createLiteralElement;
|
|
103
|
+
function createNumberElement(value, style) {
|
|
104
|
+
return {
|
|
105
|
+
type: TYPE.number,
|
|
106
|
+
value: value,
|
|
107
|
+
style: style,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
exports.createNumberElement = createNumberElement;
|