@formatjs/icu-messageformat-parser 2.11.3 → 3.0.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/lib/types.d.ts DELETED
@@ -1,120 +0,0 @@
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 type LiteralElement = BaseElement<TYPE.literal>;
64
- export type ArgumentElement = BaseElement<TYPE.argument>;
65
- export interface TagElement extends BaseElement<TYPE.tag> {
66
- children: MessageFormatElement[];
67
- }
68
- export interface SimpleFormatElement<T extends TYPE, S extends Skeleton> extends BaseElement<T> {
69
- style?: string | S | null;
70
- }
71
- export type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>;
72
- export type DateElement = SimpleFormatElement<TYPE.date, DateTimeSkeleton>;
73
- export type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>;
74
- export type ValidPluralRule = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other' | string;
75
- export interface PluralOrSelectOption {
76
- value: MessageFormatElement[];
77
- location?: Location;
78
- }
79
- export interface SelectElement extends BaseElement<TYPE.select> {
80
- options: Record<string, PluralOrSelectOption>;
81
- }
82
- export interface PluralElement extends BaseElement<TYPE.plural> {
83
- options: Record<ValidPluralRule, PluralOrSelectOption>;
84
- offset: number;
85
- pluralType: Intl.PluralRulesOptions['type'];
86
- }
87
- export interface PoundElement {
88
- type: TYPE.pound;
89
- location?: Location;
90
- }
91
- export type MessageFormatElement = ArgumentElement | DateElement | LiteralElement | NumberElement | PluralElement | PoundElement | SelectElement | TagElement | TimeElement;
92
- export interface NumberSkeleton {
93
- type: SKELETON_TYPE.number;
94
- tokens: NumberSkeletonToken[];
95
- location?: Location;
96
- parsedOptions: ExtendedNumberFormatOptions;
97
- }
98
- export interface DateTimeSkeleton {
99
- type: SKELETON_TYPE.dateTime;
100
- pattern: string;
101
- location?: Location;
102
- parsedOptions: Intl.DateTimeFormatOptions;
103
- }
104
- export type Skeleton = NumberSkeleton | DateTimeSkeleton;
105
- /**
106
- * Type Guards
107
- */
108
- export declare function isLiteralElement(el: MessageFormatElement): el is LiteralElement;
109
- export declare function isArgumentElement(el: MessageFormatElement): el is ArgumentElement;
110
- export declare function isNumberElement(el: MessageFormatElement): el is NumberElement;
111
- export declare function isDateElement(el: MessageFormatElement): el is DateElement;
112
- export declare function isTimeElement(el: MessageFormatElement): el is TimeElement;
113
- export declare function isSelectElement(el: MessageFormatElement): el is SelectElement;
114
- export declare function isPluralElement(el: MessageFormatElement): el is PluralElement;
115
- export declare function isPoundElement(el: MessageFormatElement): el is PoundElement;
116
- 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;
119
- export declare function createLiteralElement(value: string): LiteralElement;
120
- export declare function createNumberElement(value: string, style?: string | null): NumberElement;
package/lib/types.js DELETED
@@ -1,94 +0,0 @@
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 = {}));
46
- /**
47
- * Type Guards
48
- */
49
- export function isLiteralElement(el) {
50
- return el.type === TYPE.literal;
51
- }
52
- export function isArgumentElement(el) {
53
- return el.type === TYPE.argument;
54
- }
55
- export function isNumberElement(el) {
56
- return el.type === TYPE.number;
57
- }
58
- export function isDateElement(el) {
59
- return el.type === TYPE.date;
60
- }
61
- export function isTimeElement(el) {
62
- return el.type === TYPE.time;
63
- }
64
- export function isSelectElement(el) {
65
- return el.type === TYPE.select;
66
- }
67
- export function isPluralElement(el) {
68
- return el.type === TYPE.plural;
69
- }
70
- export function isPoundElement(el) {
71
- return el.type === TYPE.pound;
72
- }
73
- export function isTagElement(el) {
74
- return el.type === TYPE.tag;
75
- }
76
- export function isNumberSkeleton(el) {
77
- return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.number);
78
- }
79
- export function isDateTimeSkeleton(el) {
80
- return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.dateTime);
81
- }
82
- export function createLiteralElement(value) {
83
- return {
84
- type: TYPE.literal,
85
- value: value,
86
- };
87
- }
88
- export function createNumberElement(value, style) {
89
- return {
90
- type: TYPE.number,
91
- value: value,
92
- style: style,
93
- };
94
- }