@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/types.d.ts CHANGED
@@ -1,110 +1,113 @@
1
- import type { NumberFormatOptions } from '@formatjs/ecma402-abstract';
2
- import { NumberSkeletonToken } from '@formatjs/icu-skeleton-parser';
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
- scale?: number;
4
+ scale?: number;
5
5
  }
6
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
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
- number = 0,
47
- dateTime = 1
46
+ number = 0,
47
+ dateTime = 1
48
48
  }
49
49
  export interface LocationDetails {
50
- offset: number;
51
- line: number;
52
- column: number;
50
+ offset: number;
51
+ line: number;
52
+ column: number;
53
53
  }
54
54
  export interface Location {
55
- start: LocationDetails;
56
- end: LocationDetails;
55
+ start: LocationDetails;
56
+ end: LocationDetails;
57
57
  }
58
58
  export interface BaseElement<T extends TYPE> {
59
- type: T;
60
- value: string;
61
- location?: Location;
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
- children: MessageFormatElement[];
66
+ children: MessageFormatElement[];
67
67
  }
68
- export interface SimpleFormatElement<T extends TYPE, S extends Skeleton> extends BaseElement<T> {
69
- style?: string | S | null;
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 = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other' | string;
77
+ export type ValidPluralRule = "zero" | "one" | "two" | "few" | "many" | "other" | string;
75
78
  export interface PluralOrSelectOption {
76
- value: MessageFormatElement[];
77
- location?: Location;
79
+ value: MessageFormatElement[];
80
+ location?: Location;
78
81
  }
79
82
  export interface SelectElement extends BaseElement<TYPE.select> {
80
- options: Record<string, PluralOrSelectOption>;
83
+ options: Record<string, PluralOrSelectOption>;
81
84
  }
82
85
  export interface PluralElement extends BaseElement<TYPE.plural> {
83
- options: Record<ValidPluralRule, PluralOrSelectOption>;
84
- offset: number;
85
- pluralType: Intl.PluralRulesOptions['type'];
86
+ options: Record<ValidPluralRule, PluralOrSelectOption>;
87
+ offset: number;
88
+ pluralType: Intl.PluralRulesOptions["type"];
86
89
  }
87
90
  export interface PoundElement {
88
- type: TYPE.pound;
89
- location?: Location;
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
- type: SKELETON_TYPE.number;
94
- tokens: NumberSkeletonToken[];
95
- location?: Location;
96
- parsedOptions: ExtendedNumberFormatOptions;
96
+ type: SKELETON_TYPE.number;
97
+ tokens: NumberSkeletonToken[];
98
+ location?: Location;
99
+ parsedOptions: ExtendedNumberFormatOptions;
97
100
  }
98
101
  export interface DateTimeSkeleton {
99
- type: SKELETON_TYPE.dateTime;
100
- pattern: string;
101
- location?: Location;
102
- parsedOptions: Intl.DateTimeFormatOptions;
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
- * Type Guards
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['style'] | Skeleton): el is NumberSkeleton;
118
- export declare function isDateTimeSkeleton(el?: DateElement['style'] | TimeElement['style'] | Skeleton): el is DateTimeSkeleton;
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
- export var TYPE;
2
- (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
- })(TYPE || (TYPE = {}));
41
- export var SKELETON_TYPE;
42
- (function (SKELETON_TYPE) {
43
- SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
44
- SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
45
- })(SKELETON_TYPE || (SKELETON_TYPE = {}));
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
- * Type Guards
48
- */
48
+ * Type Guards
49
+ */
49
50
  export function isLiteralElement(el) {
50
- return el.type === TYPE.literal;
51
+ return el.type === TYPE.literal;
51
52
  }
52
53
  export function isArgumentElement(el) {
53
- return el.type === TYPE.argument;
54
+ return el.type === TYPE.argument;
54
55
  }
55
56
  export function isNumberElement(el) {
56
- return el.type === TYPE.number;
57
+ return el.type === TYPE.number;
57
58
  }
58
59
  export function isDateElement(el) {
59
- return el.type === TYPE.date;
60
+ return el.type === TYPE.date;
60
61
  }
61
62
  export function isTimeElement(el) {
62
- return el.type === TYPE.time;
63
+ return el.type === TYPE.time;
63
64
  }
64
65
  export function isSelectElement(el) {
65
- return el.type === TYPE.select;
66
+ return el.type === TYPE.select;
66
67
  }
67
68
  export function isPluralElement(el) {
68
- return el.type === TYPE.plural;
69
+ return el.type === TYPE.plural;
69
70
  }
70
71
  export function isPoundElement(el) {
71
- return el.type === TYPE.pound;
72
+ return el.type === TYPE.pound;
72
73
  }
73
74
  export function isTagElement(el) {
74
- return el.type === TYPE.tag;
75
+ return el.type === TYPE.tag;
75
76
  }
76
77
  export function isNumberSkeleton(el) {
77
- return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.number);
78
+ return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.number);
78
79
  }
79
80
  export function isDateTimeSkeleton(el) {
80
- return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.dateTime);
81
+ return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.dateTime);
81
82
  }
82
83
  export function createLiteralElement(value) {
83
- return {
84
- type: TYPE.literal,
85
- value: value,
86
- };
84
+ return {
85
+ type: TYPE.literal,
86
+ value
87
+ };
87
88
  }
88
89
  export function createNumberElement(value, style) {
89
- return {
90
- type: TYPE.number,
91
- value: value,
92
- style: style,
93
- };
90
+ return {
91
+ type: TYPE.number,
92
+ value,
93
+ style
94
+ };
94
95
  }