@common.js/formatjs__icu-messageformat-parser 3.5.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/no-parser.js ADDED
@@ -0,0 +1,261 @@
1
+ //#region packages/icu-messageformat-parser/types.ts
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ SKELETON_TYPE: function() {
14
+ return SKELETON_TYPE;
15
+ },
16
+ TYPE: function() {
17
+ return TYPE;
18
+ },
19
+ "_Parser": function() {
20
+ return _Parser;
21
+ },
22
+ createLiteralElement: function() {
23
+ return createLiteralElement;
24
+ },
25
+ createNumberElement: function() {
26
+ return createNumberElement;
27
+ },
28
+ isArgumentElement: function() {
29
+ return isArgumentElement;
30
+ },
31
+ isDateElement: function() {
32
+ return isDateElement;
33
+ },
34
+ isDateTimeSkeleton: function() {
35
+ return isDateTimeSkeleton;
36
+ },
37
+ isLiteralElement: function() {
38
+ return isLiteralElement;
39
+ },
40
+ isNumberElement: function() {
41
+ return isNumberElement;
42
+ },
43
+ isNumberSkeleton: function() {
44
+ return isNumberSkeleton;
45
+ },
46
+ isPluralElement: function() {
47
+ return isPluralElement;
48
+ },
49
+ isPoundElement: function() {
50
+ return isPoundElement;
51
+ },
52
+ isSelectElement: function() {
53
+ return isSelectElement;
54
+ },
55
+ isStructurallySame: function() {
56
+ return isStructurallySame;
57
+ },
58
+ isTagElement: function() {
59
+ return isTagElement;
60
+ },
61
+ isTimeElement: function() {
62
+ return isTimeElement;
63
+ },
64
+ parse: function() {
65
+ return parse;
66
+ }
67
+ });
68
+ function _arrayLikeToArray(arr, len) {
69
+ if (len == null || len > arr.length) len = arr.length;
70
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
71
+ return arr2;
72
+ }
73
+ function _arrayWithHoles(arr) {
74
+ if (Array.isArray(arr)) return arr;
75
+ }
76
+ function _iterableToArrayLimit(arr, i) {
77
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
78
+ if (_i == null) return;
79
+ var _arr = [];
80
+ var _n = true;
81
+ var _d = false;
82
+ var _s, _e;
83
+ try {
84
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
85
+ _arr.push(_s.value);
86
+ if (i && _arr.length === i) break;
87
+ }
88
+ } catch (err) {
89
+ _d = true;
90
+ _e = err;
91
+ } finally{
92
+ try {
93
+ if (!_n && _i["return"] != null) _i["return"]();
94
+ } finally{
95
+ if (_d) throw _e;
96
+ }
97
+ }
98
+ return _arr;
99
+ }
100
+ function _nonIterableRest() {
101
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
102
+ }
103
+ function _slicedToArray(arr, i) {
104
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
105
+ }
106
+ function _unsupportedIterableToArray(o, minLen) {
107
+ if (!o) return;
108
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
109
+ var n = Object.prototype.toString.call(o).slice(8, -1);
110
+ if (n === "Object" && o.constructor) n = o.constructor.name;
111
+ if (n === "Map" || n === "Set") return Array.from(n);
112
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
113
+ }
114
+ var TYPE = /* @__PURE__ */ function(TYPE) {
115
+ /**
116
+ * Raw text
117
+ */ TYPE[TYPE["literal"] = 0] = "literal";
118
+ /**
119
+ * Variable w/o any format, e.g `var` in `this is a {var}`
120
+ */ TYPE[TYPE["argument"] = 1] = "argument";
121
+ /**
122
+ * Variable w/ number format
123
+ */ TYPE[TYPE["number"] = 2] = "number";
124
+ /**
125
+ * Variable w/ date format
126
+ */ TYPE[TYPE["date"] = 3] = "date";
127
+ /**
128
+ * Variable w/ time format
129
+ */ TYPE[TYPE["time"] = 4] = "time";
130
+ /**
131
+ * Variable w/ select format
132
+ */ TYPE[TYPE["select"] = 5] = "select";
133
+ /**
134
+ * Variable w/ plural format
135
+ */ TYPE[TYPE["plural"] = 6] = "plural";
136
+ /**
137
+ * Only possible within plural argument.
138
+ * This is the `#` symbol that will be substituted with the count.
139
+ */ TYPE[TYPE["pound"] = 7] = "pound";
140
+ /**
141
+ * XML-like tag
142
+ */ TYPE[TYPE["tag"] = 8] = "tag";
143
+ return TYPE;
144
+ }({});
145
+ var SKELETON_TYPE = /* @__PURE__ */ function(SKELETON_TYPE) {
146
+ SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
147
+ SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
148
+ return SKELETON_TYPE;
149
+ }({});
150
+ /**
151
+ * Type Guards
152
+ */ function isLiteralElement(el) {
153
+ return el.type === 0;
154
+ }
155
+ function isArgumentElement(el) {
156
+ return el.type === 1;
157
+ }
158
+ function isNumberElement(el) {
159
+ return el.type === 2;
160
+ }
161
+ function isDateElement(el) {
162
+ return el.type === 3;
163
+ }
164
+ function isTimeElement(el) {
165
+ return el.type === 4;
166
+ }
167
+ function isSelectElement(el) {
168
+ return el.type === 5;
169
+ }
170
+ function isPluralElement(el) {
171
+ return el.type === 6;
172
+ }
173
+ function isPoundElement(el) {
174
+ return el.type === 7;
175
+ }
176
+ function isTagElement(el) {
177
+ return el.type === 8;
178
+ }
179
+ function isNumberSkeleton(el) {
180
+ return !!(el && typeof el === "object" && el.type === 0);
181
+ }
182
+ function isDateTimeSkeleton(el) {
183
+ return !!(el && typeof el === "object" && el.type === 1);
184
+ }
185
+ function createLiteralElement(value) {
186
+ return {
187
+ type: 0,
188
+ value: value
189
+ };
190
+ }
191
+ function createNumberElement(value, style) {
192
+ return {
193
+ type: 2,
194
+ value: value,
195
+ style: style
196
+ };
197
+ }
198
+ //#endregion
199
+ //#region packages/icu-messageformat-parser/manipulator.ts
200
+ /**
201
+ * Collect all variables in an AST to Record<string, TYPE>
202
+ * @param ast AST to collect variables from
203
+ * @param vars Record of variable name to variable type
204
+ */ function collectVariables(ast) {
205
+ var vars = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : /* @__PURE__ */ new Map();
206
+ ast.forEach(function(el) {
207
+ if (isArgumentElement(el) || isDateElement(el) || isTimeElement(el) || isNumberElement(el)) if (vars.has(el.value)) {
208
+ var existingType = vars.get(el.value);
209
+ if (existingType !== el.type && existingType !== 6 && existingType !== 5) throw new Error("Variable ".concat(el.value, " has conflicting types"));
210
+ } else vars.set(el.value, el.type);
211
+ if (isPluralElement(el) || isSelectElement(el)) {
212
+ vars.set(el.value, el.type);
213
+ Object.keys(el.options).forEach(function(k) {
214
+ collectVariables(el.options[k].value, vars);
215
+ });
216
+ }
217
+ if (isTagElement(el)) {
218
+ vars.set(el.value, el.type);
219
+ collectVariables(el.children, vars);
220
+ }
221
+ });
222
+ }
223
+ /**
224
+ * Check if 2 ASTs are structurally the same. This primarily means that
225
+ * they have the same variables with the same type
226
+ * @param a
227
+ * @param b
228
+ * @returns
229
+ */ function isStructurallySame(a, b) {
230
+ var aVars = /* @__PURE__ */ new Map();
231
+ var bVars = /* @__PURE__ */ new Map();
232
+ collectVariables(a, aVars);
233
+ collectVariables(b, bVars);
234
+ if (aVars.size !== bVars.size) return {
235
+ success: false,
236
+ error: /* @__PURE__ */ new Error("Different number of variables: [".concat(Array.from(aVars.keys()).join(", "), "] vs [").concat(Array.from(bVars.keys()).join(", "), "]"))
237
+ };
238
+ return Array.from(aVars.entries()).reduce(function(result, param) {
239
+ var _param = _slicedToArray(param, 2), key = _param[0], type = _param[1];
240
+ if (!result.success) return result;
241
+ var bType = bVars.get(key);
242
+ if (bType == null) return {
243
+ success: false,
244
+ error: /* @__PURE__ */ new Error("Missing variable ".concat(key, " in message"))
245
+ };
246
+ if (bType !== type) return {
247
+ success: false,
248
+ error: /* @__PURE__ */ new Error("Variable ".concat(key, " has conflicting types: ").concat(TYPE[type], " vs ").concat(TYPE[bType]))
249
+ };
250
+ return result;
251
+ }, {
252
+ success: true
253
+ });
254
+ }
255
+ //#endregion
256
+ //#region packages/icu-messageformat-parser/no-parser.ts
257
+ function parse() {
258
+ throw new Error("You're trying to format an uncompiled message with react-intl without parser, please import from 'react-intl' instead");
259
+ }
260
+ var _Parser = void 0;
261
+ //# sourceMappingURL=no-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-parser.js","names":[],"sources":["../types.ts","../manipulator.ts","../no-parser.ts"],"sourcesContent":["import type {NumberFormatOptions} from '#packages/ecma402-abstract/types/number.js'\nimport {type NumberSkeletonToken} from '@formatjs/icu-skeleton-parser'\n\nexport interface ExtendedNumberFormatOptions extends NumberFormatOptions {\n scale?: number\n}\n\nexport enum TYPE {\n /**\n * Raw text\n */\n literal,\n /**\n * Variable w/o any format, e.g `var` in `this is a {var}`\n */\n argument,\n /**\n * Variable w/ number format\n */\n number,\n /**\n * Variable w/ date format\n */\n date,\n /**\n * Variable w/ time format\n */\n time,\n /**\n * Variable w/ select format\n */\n select,\n /**\n * Variable w/ plural format\n */\n plural,\n /**\n * Only possible within plural argument.\n * This is the `#` symbol that will be substituted with the count.\n */\n pound,\n /**\n * XML-like tag\n */\n tag,\n}\n\nexport enum SKELETON_TYPE {\n number,\n dateTime,\n}\n\nexport interface LocationDetails {\n offset: number\n line: number\n column: number\n}\nexport interface Location {\n start: LocationDetails\n end: LocationDetails\n}\n\nexport interface BaseElement<T extends TYPE> {\n type: T\n value: string\n location?: Location\n}\n\nexport type LiteralElement = BaseElement<TYPE.literal>\nexport type ArgumentElement = BaseElement<TYPE.argument>\nexport interface TagElement extends BaseElement<TYPE.tag> {\n children: MessageFormatElement[]\n}\n\nexport interface SimpleFormatElement<\n T extends TYPE,\n S extends Skeleton,\n> extends BaseElement<T> {\n style?: string | S | null\n}\n\nexport type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>\nexport type DateElement = SimpleFormatElement<TYPE.date, DateTimeSkeleton>\nexport type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>\n\nexport type ValidPluralRule =\n | 'zero'\n | 'one'\n | 'two'\n | 'few'\n | 'many'\n | 'other'\n | string\n\nexport interface PluralOrSelectOption {\n value: MessageFormatElement[]\n location?: Location\n}\n\nexport interface SelectElement extends BaseElement<TYPE.select> {\n options: Record<string, PluralOrSelectOption>\n}\n\nexport interface PluralElement extends BaseElement<TYPE.plural> {\n options: Record<ValidPluralRule, PluralOrSelectOption>\n offset: number\n pluralType: Intl.PluralRulesOptions['type']\n}\n\nexport interface PoundElement {\n type: TYPE.pound\n location?: Location\n}\n\nexport type MessageFormatElement =\n | ArgumentElement\n | DateElement\n | LiteralElement\n | NumberElement\n | PluralElement\n | PoundElement\n | SelectElement\n | TagElement\n | TimeElement\n\nexport interface NumberSkeleton {\n type: SKELETON_TYPE.number\n tokens: NumberSkeletonToken[]\n location?: Location\n parsedOptions: ExtendedNumberFormatOptions\n}\n\nexport interface DateTimeSkeleton {\n type: SKELETON_TYPE.dateTime\n pattern: string\n location?: Location\n parsedOptions: Intl.DateTimeFormatOptions\n}\n\nexport type Skeleton = NumberSkeleton | DateTimeSkeleton\n\n/**\n * Type Guards\n */\nexport function isLiteralElement(\n el: MessageFormatElement\n): el is LiteralElement {\n return el.type === TYPE.literal\n}\nexport function isArgumentElement(\n el: MessageFormatElement\n): el is ArgumentElement {\n return el.type === TYPE.argument\n}\nexport function isNumberElement(el: MessageFormatElement): el is NumberElement {\n return el.type === TYPE.number\n}\nexport function isDateElement(el: MessageFormatElement): el is DateElement {\n return el.type === TYPE.date\n}\nexport function isTimeElement(el: MessageFormatElement): el is TimeElement {\n return el.type === TYPE.time\n}\nexport function isSelectElement(el: MessageFormatElement): el is SelectElement {\n return el.type === TYPE.select\n}\nexport function isPluralElement(el: MessageFormatElement): el is PluralElement {\n return el.type === TYPE.plural\n}\nexport function isPoundElement(el: MessageFormatElement): el is PoundElement {\n return el.type === TYPE.pound\n}\nexport function isTagElement(el: MessageFormatElement): el is TagElement {\n return el.type === TYPE.tag\n}\nexport function isNumberSkeleton(\n el: NumberElement['style'] | Skeleton\n): el is NumberSkeleton {\n return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.number)\n}\nexport function isDateTimeSkeleton(\n el?: DateElement['style'] | TimeElement['style'] | Skeleton\n): el is DateTimeSkeleton {\n return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.dateTime)\n}\n\nexport function createLiteralElement(value: string): LiteralElement {\n return {\n type: TYPE.literal,\n value,\n }\n}\n\nexport function createNumberElement(\n value: string,\n style?: string | null\n): NumberElement {\n return {\n type: TYPE.number,\n value,\n style,\n }\n}\n","import {\n isArgumentElement,\n isDateElement,\n isNumberElement,\n isPluralElement,\n isPoundElement,\n isSelectElement,\n isTagElement,\n isTimeElement,\n type MessageFormatElement,\n type PluralElement,\n type PluralOrSelectOption,\n type SelectElement,\n TYPE,\n} from '#packages/icu-messageformat-parser/types.js'\n\nfunction cloneDeep<T>(obj: T): T {\n if (Array.isArray(obj)) {\n // @ts-expect-error meh\n return obj.map(cloneDeep)\n }\n if (obj !== null && typeof obj === 'object') {\n // @ts-expect-error meh\n return Object.keys(obj).reduce((cloned, k) => {\n // @ts-expect-error meh\n cloned[k] = cloneDeep(obj[k])\n return cloned\n }, {})\n }\n return obj\n}\n\n/**\n * Replace pound elements with number elements referencing the given variable.\n * This is needed when nesting plurals - the # in the outer plural should become\n * an explicit variable reference when nested inside another plural.\n * GH #4202\n */\nfunction replacePoundWithArgument(\n ast: MessageFormatElement[],\n variableName: string\n): MessageFormatElement[] {\n return ast.map(el => {\n if (isPoundElement(el)) {\n // Replace # with {variableName, number}\n return {\n type: TYPE.number,\n value: variableName,\n style: null,\n location: el.location,\n }\n }\n if (isPluralElement(el) || isSelectElement(el)) {\n // Recursively process options\n const newOptions: Record<string, PluralOrSelectOption> = {}\n for (const key of Object.keys(el.options)) {\n newOptions[key] = {\n value: replacePoundWithArgument(el.options[key].value, variableName),\n }\n }\n return {...el, options: newOptions}\n }\n if (isTagElement(el)) {\n return {\n ...el,\n children: replacePoundWithArgument(el.children, variableName),\n }\n }\n return el\n })\n}\n\nfunction hoistPluralOrSelectElement(\n ast: MessageFormatElement[],\n el: PluralElement | SelectElement,\n positionToInject: number\n) {\n // pull this out of the ast and move it to the top\n const cloned = cloneDeep(el)\n const {options} = cloned\n\n // GH #4202: Check if there are other plural/select elements after this one\n const afterElements = ast.slice(positionToInject + 1)\n const hasSubsequentPluralOrSelect = afterElements.some(\n isPluralOrSelectElement\n )\n\n cloned.options = Object.keys(options).reduce(\n (all: Record<string, PluralOrSelectOption>, k) => {\n let optionValue = options[k].value\n\n // GH #4202: If there are subsequent plurals/selects and this is a plural,\n // replace # with explicit variable reference to avoid ambiguity\n if (hasSubsequentPluralOrSelect && isPluralElement(el)) {\n optionValue = replacePoundWithArgument(optionValue, el.value)\n }\n\n const newValue = hoistSelectors([\n ...ast.slice(0, positionToInject),\n ...optionValue,\n ...afterElements,\n ])\n all[k] = {\n value: newValue,\n }\n return all\n },\n {}\n )\n return cloned\n}\n\nfunction isPluralOrSelectElement(\n el: MessageFormatElement\n): el is PluralElement | SelectElement {\n return isPluralElement(el) || isSelectElement(el)\n}\n\nfunction findPluralOrSelectElement(ast: MessageFormatElement[]): boolean {\n return !!ast.find(el => {\n if (isPluralOrSelectElement(el)) {\n return true\n }\n if (isTagElement(el)) {\n return findPluralOrSelectElement(el.children)\n }\n return false\n })\n}\n\n/**\n * Hoist all selectors to the beginning of the AST & flatten the\n * resulting options. E.g:\n * \"I have {count, plural, one{a dog} other{many dogs}}\"\n * becomes \"{count, plural, one{I have a dog} other{I have many dogs}}\".\n * If there are multiple selectors, the order of which one is hoisted 1st\n * is non-deterministic.\n * The goal is to provide as many full sentences as possible since fragmented\n * sentences are not translator-friendly\n * @param ast AST\n */\nexport function hoistSelectors(\n ast: MessageFormatElement[]\n): MessageFormatElement[] {\n for (let i = 0; i < ast.length; i++) {\n const el = ast[i]\n if (isPluralOrSelectElement(el)) {\n return [hoistPluralOrSelectElement(ast, el, i)]\n }\n if (isTagElement(el) && findPluralOrSelectElement([el])) {\n throw new Error(\n 'Cannot hoist plural/select within a tag element. Please put the tag element inside each plural/select option'\n )\n }\n }\n return ast\n}\n\n/**\n * Collect all variables in an AST to Record<string, TYPE>\n * @param ast AST to collect variables from\n * @param vars Record of variable name to variable type\n */\nfunction collectVariables(\n ast: MessageFormatElement[],\n vars: Map<string, TYPE> = new Map<string, TYPE>()\n): void {\n ast.forEach(el => {\n if (\n isArgumentElement(el) ||\n isDateElement(el) ||\n isTimeElement(el) ||\n isNumberElement(el)\n ) {\n // If the variable was already registered as a plural/select, it's normal\n // for it to also appear inside as number/date/time/argument — not a conflict.\n if (vars.has(el.value)) {\n const existingType = vars.get(el.value)!\n if (\n existingType !== el.type &&\n existingType !== TYPE.plural &&\n existingType !== TYPE.select\n ) {\n throw new Error(`Variable ${el.value} has conflicting types`)\n }\n } else {\n vars.set(el.value, el.type)\n }\n }\n\n if (isPluralElement(el) || isSelectElement(el)) {\n vars.set(el.value, el.type)\n Object.keys(el.options).forEach(k => {\n collectVariables(el.options[k].value, vars)\n })\n }\n\n if (isTagElement(el)) {\n vars.set(el.value, el.type)\n collectVariables(el.children, vars)\n }\n })\n}\n\ninterface IsStructurallySameResult {\n error?: Error\n success: boolean\n}\n\n/**\n * Check if 2 ASTs are structurally the same. This primarily means that\n * they have the same variables with the same type\n * @param a\n * @param b\n * @returns\n */\nexport function isStructurallySame(\n a: MessageFormatElement[],\n b: MessageFormatElement[]\n): IsStructurallySameResult {\n const aVars = new Map<string, TYPE>()\n const bVars = new Map<string, TYPE>()\n collectVariables(a, aVars)\n collectVariables(b, bVars)\n\n if (aVars.size !== bVars.size) {\n return {\n success: false,\n error: new Error(\n `Different number of variables: [${Array.from(aVars.keys()).join(', ')}] vs [${Array.from(bVars.keys()).join(', ')}]`\n ),\n }\n }\n\n return Array.from(aVars.entries()).reduce<IsStructurallySameResult>(\n (result, [key, type]) => {\n if (!result.success) {\n return result\n }\n const bType = bVars.get(key)\n if (bType == null) {\n return {\n success: false,\n error: new Error(`Missing variable ${key} in message`),\n }\n }\n if (bType !== type) {\n return {\n success: false,\n error: new Error(\n `Variable ${key} has conflicting types: ${TYPE[type]} vs ${TYPE[bType]}`\n ),\n }\n }\n return result\n },\n {success: true}\n )\n}\n","export function parse(): void {\n throw new Error(\n \"You're trying to format an uncompiled message with react-intl without parser, please import from 'react-intl' instead\"\n )\n}\nexport * from '#packages/icu-messageformat-parser/types.js'\nexport const _Parser = undefined\nexport {isStructurallySame} from '#packages/icu-messageformat-parser/manipulator.js'\n"],"mappings":"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"}
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@common.js/formatjs__icu-messageformat-parser",
3
+ "version": "3.5.12",
4
+ "license": "MIT",
5
+ "repository": "etienne-martin/common.js",
6
+ "type": "commonjs",
7
+ "types": "index.d.ts",
8
+ "dependencies": {
9
+ "@common.js/formatjs__icu-skeleton-parser": "2.1.10"
10
+ },
11
+ "homepage": "https://github.com/etienne-martin/common.js#readme",
12
+ "description": "@formatjs/icu-messageformat-parser package exported as CommonJS modules",
13
+ "scripts": {},
14
+ "main": "./index.js"
15
+ }
package/printer.d.ts ADDED
@@ -0,0 +1,156 @@
1
+ import { NumberSkeletonToken } from "@formatjs/icu-skeleton-parser";
2
+
3
+ //#region packages/ecma402-abstract/types/number.d.ts
4
+ type NumberFormatNotation = "standard" | "scientific" | "engineering" | "compact";
5
+ type RoundingPriorityType = "auto" | "morePrecision" | "lessPrecision";
6
+ type RoundingModeType = "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven";
7
+ type UseGroupingType = "min2" | "auto" | "always" | boolean;
8
+ interface NumberFormatDigitOptions {
9
+ minimumIntegerDigits?: number;
10
+ minimumSignificantDigits?: number;
11
+ maximumSignificantDigits?: number;
12
+ minimumFractionDigits?: number;
13
+ maximumFractionDigits?: number;
14
+ roundingPriority?: RoundingPriorityType;
15
+ roundingIncrement?: number;
16
+ roundingMode?: RoundingModeType;
17
+ trailingZeroDisplay?: TrailingZeroDisplay;
18
+ }
19
+ type NumberFormatOptionsLocaleMatcher = "lookup" | "best fit";
20
+ type NumberFormatOptionsStyle = "decimal" | "percent" | "currency" | "unit";
21
+ type NumberFormatOptionsCompactDisplay = "short" | "long";
22
+ type NumberFormatOptionsCurrencyDisplay = "symbol" | "code" | "name" | "narrowSymbol";
23
+ type NumberFormatOptionsCurrencySign = "standard" | "accounting";
24
+ type NumberFormatOptionsNotation = NumberFormatNotation;
25
+ type NumberFormatOptionsSignDisplay = "auto" | "always" | "never" | "exceptZero" | "negative";
26
+ type NumberFormatOptionsUnitDisplay = "long" | "short" | "narrow";
27
+ type TrailingZeroDisplay = "auto" | "stripIfInteger";
28
+ type NumberFormatOptions = Omit<Intl.NumberFormatOptions, "signDisplay" | "useGrouping"> & NumberFormatDigitOptions & {
29
+ localeMatcher?: NumberFormatOptionsLocaleMatcher;
30
+ style?: NumberFormatOptionsStyle;
31
+ compactDisplay?: NumberFormatOptionsCompactDisplay;
32
+ currencyDisplay?: NumberFormatOptionsCurrencyDisplay;
33
+ currencySign?: NumberFormatOptionsCurrencySign;
34
+ notation?: NumberFormatOptionsNotation;
35
+ signDisplay?: NumberFormatOptionsSignDisplay;
36
+ unit?: string;
37
+ unitDisplay?: NumberFormatOptionsUnitDisplay;
38
+ numberingSystem?: string;
39
+ trailingZeroDisplay?: TrailingZeroDisplay;
40
+ roundingPriority?: RoundingPriorityType;
41
+ roundingIncrement?: number;
42
+ roundingMode?: RoundingModeType;
43
+ useGrouping?: UseGroupingType;
44
+ };
45
+ //#endregion
46
+ //#region packages/icu-messageformat-parser/types.d.ts
47
+ interface ExtendedNumberFormatOptions extends NumberFormatOptions {
48
+ scale?: number;
49
+ }
50
+ declare enum TYPE {
51
+ /**
52
+ * Raw text
53
+ */
54
+ literal = 0,
55
+ /**
56
+ * Variable w/o any format, e.g `var` in `this is a {var}`
57
+ */
58
+ argument = 1,
59
+ /**
60
+ * Variable w/ number format
61
+ */
62
+ number = 2,
63
+ /**
64
+ * Variable w/ date format
65
+ */
66
+ date = 3,
67
+ /**
68
+ * Variable w/ time format
69
+ */
70
+ time = 4,
71
+ /**
72
+ * Variable w/ select format
73
+ */
74
+ select = 5,
75
+ /**
76
+ * Variable w/ plural format
77
+ */
78
+ plural = 6,
79
+ /**
80
+ * Only possible within plural argument.
81
+ * This is the `#` symbol that will be substituted with the count.
82
+ */
83
+ pound = 7,
84
+ /**
85
+ * XML-like tag
86
+ */
87
+ tag = 8
88
+ }
89
+ declare enum SKELETON_TYPE {
90
+ number = 0,
91
+ dateTime = 1
92
+ }
93
+ interface LocationDetails {
94
+ offset: number;
95
+ line: number;
96
+ column: number;
97
+ }
98
+ interface Location {
99
+ start: LocationDetails;
100
+ end: LocationDetails;
101
+ }
102
+ interface BaseElement<T extends TYPE> {
103
+ type: T;
104
+ value: string;
105
+ location?: Location;
106
+ }
107
+ type LiteralElement = BaseElement<TYPE.literal>;
108
+ type ArgumentElement = BaseElement<TYPE.argument>;
109
+ interface TagElement extends BaseElement<TYPE.tag> {
110
+ children: MessageFormatElement[];
111
+ }
112
+ interface SimpleFormatElement<T extends TYPE, S extends Skeleton> extends BaseElement<T> {
113
+ style?: string | S | null;
114
+ }
115
+ type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>;
116
+ type DateElement = SimpleFormatElement<TYPE.date, DateTimeSkeleton>;
117
+ type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>;
118
+ type ValidPluralRule = "zero" | "one" | "two" | "few" | "many" | "other" | string;
119
+ interface PluralOrSelectOption {
120
+ value: MessageFormatElement[];
121
+ location?: Location;
122
+ }
123
+ interface SelectElement extends BaseElement<TYPE.select> {
124
+ options: Record<string, PluralOrSelectOption>;
125
+ }
126
+ interface PluralElement extends BaseElement<TYPE.plural> {
127
+ options: Record<ValidPluralRule, PluralOrSelectOption>;
128
+ offset: number;
129
+ pluralType: Intl.PluralRulesOptions["type"];
130
+ }
131
+ interface PoundElement {
132
+ type: TYPE.pound;
133
+ location?: Location;
134
+ }
135
+ type MessageFormatElement = ArgumentElement | DateElement | LiteralElement | NumberElement | PluralElement | PoundElement | SelectElement | TagElement | TimeElement;
136
+ interface NumberSkeleton {
137
+ type: SKELETON_TYPE.number;
138
+ tokens: NumberSkeletonToken[];
139
+ location?: Location;
140
+ parsedOptions: ExtendedNumberFormatOptions;
141
+ }
142
+ interface DateTimeSkeleton {
143
+ type: SKELETON_TYPE.dateTime;
144
+ pattern: string;
145
+ location?: Location;
146
+ parsedOptions: Intl.DateTimeFormatOptions;
147
+ }
148
+ type Skeleton = NumberSkeleton | DateTimeSkeleton;
149
+ //#endregion
150
+ //#region packages/icu-messageformat-parser/printer.d.ts
151
+ declare function printAST(ast: MessageFormatElement[]): string;
152
+ declare function doPrintAST(ast: MessageFormatElement[], isInPlural: boolean): string;
153
+ declare function printDateTimeSkeleton(style: DateTimeSkeleton): string;
154
+ //#endregion
155
+ export { doPrintAST, printAST, printDateTimeSkeleton };
156
+ //# sourceMappingURL=printer.d.ts.map