@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/types.d.ts
CHANGED
|
@@ -1,110 +1,113 @@
|
|
|
1
|
-
import type { NumberFormatOptions } from
|
|
2
|
-
import { NumberSkeletonToken } from
|
|
1
|
+
import type { NumberFormatOptions } from "@formatjs/ecma402-abstract";
|
|
2
|
+
import { type NumberSkeletonToken } from "@formatjs/icu-skeleton-parser";
|
|
3
3
|
export interface ExtendedNumberFormatOptions extends NumberFormatOptions {
|
|
4
|
-
|
|
4
|
+
scale?: number;
|
|
5
5
|
}
|
|
6
6
|
export declare enum TYPE {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
44
|
}
|
|
45
45
|
export declare enum SKELETON_TYPE {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
number = 0,
|
|
47
|
+
dateTime = 1
|
|
48
48
|
}
|
|
49
49
|
export interface LocationDetails {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
offset: number;
|
|
51
|
+
line: number;
|
|
52
|
+
column: number;
|
|
53
53
|
}
|
|
54
54
|
export interface Location {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
start: LocationDetails;
|
|
56
|
+
end: LocationDetails;
|
|
57
57
|
}
|
|
58
58
|
export interface BaseElement<T extends TYPE> {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
type: T;
|
|
60
|
+
value: string;
|
|
61
|
+
location?: Location;
|
|
62
62
|
}
|
|
63
63
|
export type LiteralElement = BaseElement<TYPE.literal>;
|
|
64
64
|
export type ArgumentElement = BaseElement<TYPE.argument>;
|
|
65
65
|
export interface TagElement extends BaseElement<TYPE.tag> {
|
|
66
|
-
|
|
66
|
+
children: MessageFormatElement[];
|
|
67
67
|
}
|
|
68
|
-
export interface SimpleFormatElement<
|
|
69
|
-
|
|
68
|
+
export interface SimpleFormatElement<
|
|
69
|
+
T extends TYPE,
|
|
70
|
+
S extends Skeleton
|
|
71
|
+
> extends BaseElement<T> {
|
|
72
|
+
style?: string | S | null;
|
|
70
73
|
}
|
|
71
74
|
export type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>;
|
|
72
75
|
export type DateElement = SimpleFormatElement<TYPE.date, DateTimeSkeleton>;
|
|
73
76
|
export type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>;
|
|
74
|
-
export type ValidPluralRule =
|
|
77
|
+
export type ValidPluralRule = "zero" | "one" | "two" | "few" | "many" | "other" | string;
|
|
75
78
|
export interface PluralOrSelectOption {
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
value: MessageFormatElement[];
|
|
80
|
+
location?: Location;
|
|
78
81
|
}
|
|
79
82
|
export interface SelectElement extends BaseElement<TYPE.select> {
|
|
80
|
-
|
|
83
|
+
options: Record<string, PluralOrSelectOption>;
|
|
81
84
|
}
|
|
82
85
|
export interface PluralElement extends BaseElement<TYPE.plural> {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
options: Record<ValidPluralRule, PluralOrSelectOption>;
|
|
87
|
+
offset: number;
|
|
88
|
+
pluralType: Intl.PluralRulesOptions["type"];
|
|
86
89
|
}
|
|
87
90
|
export interface PoundElement {
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
type: TYPE.pound;
|
|
92
|
+
location?: Location;
|
|
90
93
|
}
|
|
91
94
|
export type MessageFormatElement = ArgumentElement | DateElement | LiteralElement | NumberElement | PluralElement | PoundElement | SelectElement | TagElement | TimeElement;
|
|
92
95
|
export interface NumberSkeleton {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
type: SKELETON_TYPE.number;
|
|
97
|
+
tokens: NumberSkeletonToken[];
|
|
98
|
+
location?: Location;
|
|
99
|
+
parsedOptions: ExtendedNumberFormatOptions;
|
|
97
100
|
}
|
|
98
101
|
export interface DateTimeSkeleton {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
type: SKELETON_TYPE.dateTime;
|
|
103
|
+
pattern: string;
|
|
104
|
+
location?: Location;
|
|
105
|
+
parsedOptions: Intl.DateTimeFormatOptions;
|
|
103
106
|
}
|
|
104
107
|
export type Skeleton = NumberSkeleton | DateTimeSkeleton;
|
|
105
108
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
* Type Guards
|
|
110
|
+
*/
|
|
108
111
|
export declare function isLiteralElement(el: MessageFormatElement): el is LiteralElement;
|
|
109
112
|
export declare function isArgumentElement(el: MessageFormatElement): el is ArgumentElement;
|
|
110
113
|
export declare function isNumberElement(el: MessageFormatElement): el is NumberElement;
|
|
@@ -114,7 +117,7 @@ export declare function isSelectElement(el: MessageFormatElement): el is SelectE
|
|
|
114
117
|
export declare function isPluralElement(el: MessageFormatElement): el is PluralElement;
|
|
115
118
|
export declare function isPoundElement(el: MessageFormatElement): el is PoundElement;
|
|
116
119
|
export declare function isTagElement(el: MessageFormatElement): el is TagElement;
|
|
117
|
-
export declare function isNumberSkeleton(el: NumberElement[
|
|
118
|
-
export declare function isDateTimeSkeleton(el?: DateElement[
|
|
120
|
+
export declare function isNumberSkeleton(el: NumberElement["style"] | Skeleton): el is NumberSkeleton;
|
|
121
|
+
export declare function isDateTimeSkeleton(el?: DateElement["style"] | TimeElement["style"] | Skeleton): el is DateTimeSkeleton;
|
|
119
122
|
export declare function createLiteralElement(value: string): LiteralElement;
|
|
120
123
|
export declare function createNumberElement(value: string, style?: string | null): NumberElement;
|
package/types.js
CHANGED
|
@@ -1,94 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
import "@formatjs/icu-skeleton-parser";
|
|
2
|
+
export let TYPE = /* @__PURE__ */ function(TYPE) {
|
|
3
|
+
/**
|
|
4
|
+
* Raw text
|
|
5
|
+
*/
|
|
6
|
+
TYPE[TYPE["literal"] = 0] = "literal";
|
|
7
|
+
/**
|
|
8
|
+
* Variable w/o any format, e.g `var` in `this is a {var}`
|
|
9
|
+
*/
|
|
10
|
+
TYPE[TYPE["argument"] = 1] = "argument";
|
|
11
|
+
/**
|
|
12
|
+
* Variable w/ number format
|
|
13
|
+
*/
|
|
14
|
+
TYPE[TYPE["number"] = 2] = "number";
|
|
15
|
+
/**
|
|
16
|
+
* Variable w/ date format
|
|
17
|
+
*/
|
|
18
|
+
TYPE[TYPE["date"] = 3] = "date";
|
|
19
|
+
/**
|
|
20
|
+
* Variable w/ time format
|
|
21
|
+
*/
|
|
22
|
+
TYPE[TYPE["time"] = 4] = "time";
|
|
23
|
+
/**
|
|
24
|
+
* Variable w/ select format
|
|
25
|
+
*/
|
|
26
|
+
TYPE[TYPE["select"] = 5] = "select";
|
|
27
|
+
/**
|
|
28
|
+
* Variable w/ plural format
|
|
29
|
+
*/
|
|
30
|
+
TYPE[TYPE["plural"] = 6] = "plural";
|
|
31
|
+
/**
|
|
32
|
+
* Only possible within plural argument.
|
|
33
|
+
* This is the `#` symbol that will be substituted with the count.
|
|
34
|
+
*/
|
|
35
|
+
TYPE[TYPE["pound"] = 7] = "pound";
|
|
36
|
+
/**
|
|
37
|
+
* XML-like tag
|
|
38
|
+
*/
|
|
39
|
+
TYPE[TYPE["tag"] = 8] = "tag";
|
|
40
|
+
return TYPE;
|
|
41
|
+
}({});
|
|
42
|
+
export let SKELETON_TYPE = /* @__PURE__ */ function(SKELETON_TYPE) {
|
|
43
|
+
SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
|
|
44
|
+
SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
|
|
45
|
+
return SKELETON_TYPE;
|
|
46
|
+
}({});
|
|
46
47
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
* Type Guards
|
|
49
|
+
*/
|
|
49
50
|
export function isLiteralElement(el) {
|
|
50
|
-
|
|
51
|
+
return el.type === TYPE.literal;
|
|
51
52
|
}
|
|
52
53
|
export function isArgumentElement(el) {
|
|
53
|
-
|
|
54
|
+
return el.type === TYPE.argument;
|
|
54
55
|
}
|
|
55
56
|
export function isNumberElement(el) {
|
|
56
|
-
|
|
57
|
+
return el.type === TYPE.number;
|
|
57
58
|
}
|
|
58
59
|
export function isDateElement(el) {
|
|
59
|
-
|
|
60
|
+
return el.type === TYPE.date;
|
|
60
61
|
}
|
|
61
62
|
export function isTimeElement(el) {
|
|
62
|
-
|
|
63
|
+
return el.type === TYPE.time;
|
|
63
64
|
}
|
|
64
65
|
export function isSelectElement(el) {
|
|
65
|
-
|
|
66
|
+
return el.type === TYPE.select;
|
|
66
67
|
}
|
|
67
68
|
export function isPluralElement(el) {
|
|
68
|
-
|
|
69
|
+
return el.type === TYPE.plural;
|
|
69
70
|
}
|
|
70
71
|
export function isPoundElement(el) {
|
|
71
|
-
|
|
72
|
+
return el.type === TYPE.pound;
|
|
72
73
|
}
|
|
73
74
|
export function isTagElement(el) {
|
|
74
|
-
|
|
75
|
+
return el.type === TYPE.tag;
|
|
75
76
|
}
|
|
76
77
|
export function isNumberSkeleton(el) {
|
|
77
|
-
|
|
78
|
+
return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.number);
|
|
78
79
|
}
|
|
79
80
|
export function isDateTimeSkeleton(el) {
|
|
80
|
-
|
|
81
|
+
return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.dateTime);
|
|
81
82
|
}
|
|
82
83
|
export function createLiteralElement(value) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
return {
|
|
85
|
+
type: TYPE.literal,
|
|
86
|
+
value
|
|
87
|
+
};
|
|
87
88
|
}
|
|
88
89
|
export function createNumberElement(value, style) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
return {
|
|
91
|
+
type: TYPE.number,
|
|
92
|
+
value,
|
|
93
|
+
style
|
|
94
|
+
};
|
|
94
95
|
}
|