intl-messageformat 11.2.6 → 11.2.8
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/index.js +14 -14
- package/index.js.map +1 -1
- package/intl-messageformat.iife.js +113 -109
- package/package.json +22 -23
package/index.js
CHANGED
|
@@ -19,17 +19,17 @@ var FormatError = class extends Error {
|
|
|
19
19
|
};
|
|
20
20
|
var InvalidValueError = class extends FormatError {
|
|
21
21
|
constructor(variableId, value, options, originalMessage) {
|
|
22
|
-
super(`Invalid values for "${variableId}": "${value}". Options are "${Object.keys(options).join("\", \"")}"`,
|
|
22
|
+
super(`Invalid values for "${variableId}": "${value}". Options are "${Object.keys(options).join("\", \"")}"`, "INVALID_VALUE", originalMessage);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
var InvalidValueTypeError = class extends FormatError {
|
|
26
26
|
constructor(value, type, originalMessage) {
|
|
27
|
-
super(`Value for "${value}" must be of type ${type}`,
|
|
27
|
+
super(`Value for "${value}" must be of type ${type}`, "INVALID_VALUE", originalMessage);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
var MissingValueError = class extends FormatError {
|
|
31
31
|
constructor(variableId, originalMessage) {
|
|
32
|
-
super(`The intl string context variable "${variableId}" was not provided to the string "${originalMessage}"`,
|
|
32
|
+
super(`The intl string context variable "${variableId}" was not provided to the string "${originalMessage}"`, "MISSING_VALUE", originalMessage);
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
//#endregion
|
|
@@ -43,7 +43,7 @@ function mergeLiteral(parts) {
|
|
|
43
43
|
if (parts.length < 2) return parts;
|
|
44
44
|
return parts.reduce((all, part) => {
|
|
45
45
|
const lastPart = all[all.length - 1];
|
|
46
|
-
if (!lastPart || lastPart.type !==
|
|
46
|
+
if (!lastPart || lastPart.type !== 0 || part.type !== 0) all.push(part);
|
|
47
47
|
else lastPart.value += part.value;
|
|
48
48
|
return all;
|
|
49
49
|
}, []);
|
|
@@ -53,21 +53,21 @@ function isFormatXMLElementFn(el) {
|
|
|
53
53
|
}
|
|
54
54
|
function formatToParts(els, locales, formatters, formats, values, currentPluralValue, originalMessage) {
|
|
55
55
|
if (els.length === 1 && isLiteralElement(els[0])) return [{
|
|
56
|
-
type:
|
|
56
|
+
type: 0,
|
|
57
57
|
value: els[0].value
|
|
58
58
|
}];
|
|
59
59
|
const result = [];
|
|
60
60
|
for (const el of els) {
|
|
61
61
|
if (isLiteralElement(el)) {
|
|
62
62
|
result.push({
|
|
63
|
-
type:
|
|
63
|
+
type: 0,
|
|
64
64
|
value: el.value
|
|
65
65
|
});
|
|
66
66
|
continue;
|
|
67
67
|
}
|
|
68
68
|
if (isPoundElement(el)) {
|
|
69
69
|
if (typeof currentPluralValue === "number") result.push({
|
|
70
|
-
type:
|
|
70
|
+
type: 0,
|
|
71
71
|
value: formatters.getNumberFormat(locales).format(currentPluralValue)
|
|
72
72
|
});
|
|
73
73
|
continue;
|
|
@@ -78,7 +78,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
78
78
|
if (isArgumentElement(el)) {
|
|
79
79
|
if (!value || typeof value === "string" || typeof value === "number" || typeof value === "bigint") value = typeof value === "string" || typeof value === "number" || typeof value === "bigint" ? String(value) : "";
|
|
80
80
|
result.push({
|
|
81
|
-
type: typeof value === "string" ?
|
|
81
|
+
type: typeof value === "string" ? 0 : 1,
|
|
82
82
|
value
|
|
83
83
|
});
|
|
84
84
|
continue;
|
|
@@ -86,7 +86,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
86
86
|
if (isDateElement(el)) {
|
|
87
87
|
const style = typeof el.style === "string" ? formats.date[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : void 0;
|
|
88
88
|
result.push({
|
|
89
|
-
type:
|
|
89
|
+
type: 0,
|
|
90
90
|
value: formatters.getDateTimeFormat(locales, style).format(value)
|
|
91
91
|
});
|
|
92
92
|
continue;
|
|
@@ -94,7 +94,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
94
94
|
if (isTimeElement(el)) {
|
|
95
95
|
const style = typeof el.style === "string" ? formats.time[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : formats.time.medium;
|
|
96
96
|
result.push({
|
|
97
|
-
type:
|
|
97
|
+
type: 0,
|
|
98
98
|
value: formatters.getDateTimeFormat(locales, style).format(value)
|
|
99
99
|
});
|
|
100
100
|
continue;
|
|
@@ -109,7 +109,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
109
109
|
} else value = value * scale;
|
|
110
110
|
}
|
|
111
111
|
result.push({
|
|
112
|
-
type:
|
|
112
|
+
type: 0,
|
|
113
113
|
value: formatters.getNumberFormat(locales, style).format(value)
|
|
114
114
|
});
|
|
115
115
|
continue;
|
|
@@ -122,7 +122,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
122
122
|
if (!Array.isArray(chunks)) chunks = [chunks];
|
|
123
123
|
result.push(...chunks.map((c) => {
|
|
124
124
|
return {
|
|
125
|
-
type: typeof c === "string" ?
|
|
125
|
+
type: typeof c === "string" ? 0 : 1,
|
|
126
126
|
value: c
|
|
127
127
|
};
|
|
128
128
|
}));
|
|
@@ -140,7 +140,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
140
140
|
if (!opt) {
|
|
141
141
|
if (!Intl.PluralRules) throw new FormatError(`Intl.PluralRules is not available in this environment.
|
|
142
142
|
Try polyfilling it using "@formatjs/intl-pluralrules"
|
|
143
|
-
`,
|
|
143
|
+
`, "MISSING_INTL_API", originalMessage);
|
|
144
144
|
const numericValue = typeof value === "bigint" ? Number(value) : value;
|
|
145
145
|
const rule = formatters.getPluralRules(locales, { type: el.pluralType }).select(numericValue - (el.offset || 0));
|
|
146
146
|
opt = (Object.prototype.hasOwnProperty.call(el.options, rule) ? el.options[rule] : void 0) || el.options.other;
|
|
@@ -219,7 +219,7 @@ var IntlMessageFormat = class IntlMessageFormat {
|
|
|
219
219
|
const parts = this.formatToParts(values);
|
|
220
220
|
if (parts.length === 1) return parts[0].value;
|
|
221
221
|
const result = parts.reduce((all, part) => {
|
|
222
|
-
if (!all.length || part.type !==
|
|
222
|
+
if (!all.length || part.type !== 0 || typeof all[all.length - 1] !== "string") all.push(part.value);
|
|
223
223
|
else all[all.length - 1] += part.value;
|
|
224
224
|
return all;
|
|
225
225
|
}, []);
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../error.ts","../formatters.ts","../core.ts","../index.ts"],"sourcesContent":["export enum ErrorCode {\n // When we have a placeholder but no value to format\n MISSING_VALUE = 'MISSING_VALUE',\n // When value supplied is invalid\n INVALID_VALUE = 'INVALID_VALUE',\n // When we need specific Intl API but it's not available\n MISSING_INTL_API = 'MISSING_INTL_API',\n}\n\nexport class FormatError extends Error {\n public readonly code: ErrorCode\n /**\n * Original message we're trying to format\n * `undefined` if we're only dealing w/ AST\n *\n * @type {(string | undefined)}\n * @memberof FormatError\n */\n public readonly originalMessage: string | undefined\n constructor(msg: string, code: ErrorCode, originalMessage?: string) {\n super(msg)\n this.code = code\n this.originalMessage = originalMessage\n }\n public toString() {\n return `[formatjs Error: ${this.code}] ${this.message}`\n }\n}\n\nexport class InvalidValueError extends FormatError {\n constructor(\n variableId: string,\n value: any,\n options: string[],\n originalMessage?: string\n ) {\n super(\n `Invalid values for \"${variableId}\": \"${value}\". Options are \"${Object.keys(\n options\n ).join('\", \"')}\"`,\n ErrorCode.INVALID_VALUE,\n originalMessage\n )\n }\n}\n\nexport class InvalidValueTypeError extends FormatError {\n constructor(value: any, type: string, originalMessage?: string) {\n super(\n `Value for \"${value}\" must be of type ${type}`,\n ErrorCode.INVALID_VALUE,\n originalMessage\n )\n }\n}\n\nexport class MissingValueError extends FormatError {\n constructor(variableId: string, originalMessage?: string) {\n super(\n `The intl string context variable \"${variableId}\" was not provided to the string \"${originalMessage}\"`,\n ErrorCode.MISSING_VALUE,\n originalMessage\n )\n }\n}\n","import {type NumberFormatOptions} from '#packages/ecma402-abstract/types/number.js'\nimport {\n type ExtendedNumberFormatOptions,\n isArgumentElement,\n isDateElement,\n isDateTimeSkeleton,\n isLiteralElement,\n isNumberElement,\n isNumberSkeleton,\n isPluralElement,\n isPoundElement,\n isSelectElement,\n isTagElement,\n isTimeElement,\n type MessageFormatElement,\n} from '@formatjs/icu-messageformat-parser'\nimport {\n ErrorCode,\n FormatError,\n InvalidValueError,\n InvalidValueTypeError,\n MissingValueError,\n} from '#packages/intl-messageformat/error.js'\n\ndeclare global {\n namespace FormatjsIntl {\n interface Message {}\n interface IntlConfig {}\n interface Formats {}\n }\n}\n\ntype Format<Source = string> = Source extends keyof FormatjsIntl.Formats\n ? FormatjsIntl.Formats[Source]\n : string\n\nexport interface Formats {\n number: Record<Format<'number'>, NumberFormatOptions>\n date: Record<Format<'date'>, Intl.DateTimeFormatOptions>\n time: Record<Format<'time'>, Intl.DateTimeFormatOptions>\n}\n\nexport interface FormatterCache {\n number: Record<string, NumberFormatOptions>\n dateTime: Record<string, Intl.DateTimeFormat>\n pluralRules: Record<string, Intl.PluralRules>\n}\n\nexport interface Formatters {\n getNumberFormat(\n locals?: string | string[],\n opts?: NumberFormatOptions\n ): Intl.NumberFormat\n getDateTimeFormat(\n ...args: ConstructorParameters<typeof Intl.DateTimeFormat>\n ): Intl.DateTimeFormat\n getPluralRules(\n ...args: ConstructorParameters<typeof Intl.PluralRules>\n ): Intl.PluralRules\n}\n\nexport enum PART_TYPE {\n literal,\n object,\n}\n\nexport interface LiteralPart {\n type: PART_TYPE.literal\n value: string\n}\n\nexport interface ObjectPart<T = any> {\n type: PART_TYPE.object\n value: T\n}\n\nexport type MessageFormatPart<T> = LiteralPart | ObjectPart<T>\n\nexport type PrimitiveType =\n | string\n | number\n | bigint\n | boolean\n | null\n | undefined\n | Date\n\nfunction mergeLiteral<T>(\n parts: MessageFormatPart<T>[]\n): MessageFormatPart<T>[] {\n if (parts.length < 2) {\n return parts\n }\n return parts.reduce((all, part) => {\n const lastPart = all[all.length - 1]\n if (\n !lastPart ||\n lastPart.type !== PART_TYPE.literal ||\n part.type !== PART_TYPE.literal\n ) {\n all.push(part)\n } else {\n lastPart.value += part.value\n }\n return all\n }, [] as MessageFormatPart<T>[])\n}\n\nexport function isFormatXMLElementFn<T>(\n el: PrimitiveType | T | FormatXMLElementFn<T>\n): el is FormatXMLElementFn<T> {\n return typeof el === 'function'\n}\n\n// TODO(skeleton): add skeleton support\nexport function formatToParts<T>(\n els: MessageFormatElement[],\n locales: string | string[],\n formatters: Formatters,\n formats: Formats,\n values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>,\n currentPluralValue?: number,\n // For debugging\n originalMessage?: string\n): MessageFormatPart<T>[] {\n // Hot path for straight simple msg translations\n if (els.length === 1 && isLiteralElement(els[0])) {\n return [\n {\n type: PART_TYPE.literal,\n value: els[0].value,\n },\n ]\n }\n const result: MessageFormatPart<T>[] = []\n for (const el of els) {\n // Exit early for string parts.\n if (isLiteralElement(el)) {\n result.push({\n type: PART_TYPE.literal,\n value: el.value,\n })\n continue\n }\n // TODO: should this part be literal type?\n // Replace `#` in plural rules with the actual numeric value.\n if (isPoundElement(el)) {\n if (typeof currentPluralValue === 'number') {\n result.push({\n type: PART_TYPE.literal,\n value: formatters.getNumberFormat(locales).format(currentPluralValue),\n })\n }\n continue\n }\n\n const {value: varName} = el\n\n // Enforce that all required values are provided by the caller.\n if (!(values && varName in values)) {\n throw new MissingValueError(varName, originalMessage)\n }\n\n let value = values[varName]\n if (isArgumentElement(el)) {\n if (\n !value ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'bigint'\n ) {\n value =\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'bigint'\n ? String(value)\n : ''\n }\n result.push({\n type: typeof value === 'string' ? PART_TYPE.literal : PART_TYPE.object,\n value,\n } as ObjectPart<T>)\n continue\n }\n\n // Recursively format plural and select parts' option — which can be a\n // nested pattern structure. The choosing of the option to use is\n // abstracted-by and delegated-to the part helper object.\n if (isDateElement(el)) {\n const style =\n typeof el.style === 'string'\n ? formats.date[el.style]\n : isDateTimeSkeleton(el.style)\n ? el.style.parsedOptions\n : undefined\n result.push({\n type: PART_TYPE.literal,\n value: formatters\n .getDateTimeFormat(locales, style)\n .format(value as number),\n })\n continue\n }\n if (isTimeElement(el)) {\n const style =\n typeof el.style === 'string'\n ? formats.time[el.style]\n : isDateTimeSkeleton(el.style)\n ? el.style.parsedOptions\n : formats.time.medium\n result.push({\n type: PART_TYPE.literal,\n value: formatters\n .getDateTimeFormat(locales, style)\n .format(value as number),\n })\n continue\n }\n if (isNumberElement(el)) {\n const style =\n typeof el.style === 'string'\n ? formats.number[el.style]\n : isNumberSkeleton(el.style)\n ? el.style.parsedOptions\n : undefined\n\n if (style && (style as ExtendedNumberFormatOptions).scale) {\n const scale = (style as ExtendedNumberFormatOptions).scale || 1\n // Handle bigint scale multiplication\n // BigInt can only be multiplied by BigInt\n if (typeof value === 'bigint') {\n // Check if scale is a safe integer that can be converted to BigInt\n if (!Number.isInteger(scale)) {\n throw new TypeError(\n `Cannot apply fractional scale ${scale} to bigint value. Scale must be an integer when formatting bigint.`\n )\n }\n value = value * BigInt(scale)\n } else {\n value = (value as number) * scale\n }\n }\n result.push({\n type: PART_TYPE.literal,\n value: formatters\n .getNumberFormat(locales, style)\n .format(value as number | bigint),\n })\n continue\n }\n if (isTagElement(el)) {\n const {children, value} = el\n const formatFn = values[value]\n if (!isFormatXMLElementFn<T>(formatFn)) {\n throw new InvalidValueTypeError(value, 'function', originalMessage)\n }\n const parts = formatToParts<T>(\n children,\n locales,\n formatters,\n formats,\n values,\n currentPluralValue\n )\n let chunks = formatFn(parts.map(p => p.value))\n if (!Array.isArray(chunks)) {\n chunks = [chunks]\n }\n result.push(\n ...chunks.map((c): MessageFormatPart<T> => {\n return {\n type: typeof c === 'string' ? PART_TYPE.literal : PART_TYPE.object,\n value: c,\n } as MessageFormatPart<T>\n })\n )\n }\n if (isSelectElement(el)) {\n // GH #4490: Use hasOwnProperty to avoid prototype chain issues with keys like \"constructor\"\n const key = value as string\n const opt =\n (Object.prototype.hasOwnProperty.call(el.options, key)\n ? el.options[key]\n : undefined) || el.options.other\n if (!opt) {\n throw new InvalidValueError(\n el.value,\n value,\n Object.keys(el.options),\n originalMessage\n )\n }\n result.push(\n ...formatToParts(opt.value, locales, formatters, formats, values)\n )\n continue\n }\n if (isPluralElement(el)) {\n // GH #4490: Use hasOwnProperty to avoid prototype chain issues\n const exactKey = `=${value}`\n let opt = Object.prototype.hasOwnProperty.call(el.options, exactKey)\n ? el.options[exactKey]\n : undefined\n if (!opt) {\n if (!Intl.PluralRules) {\n throw new FormatError(\n `Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n`,\n ErrorCode.MISSING_INTL_API,\n originalMessage\n )\n }\n // Convert bigint to number for PluralRules (which only accepts number)\n const numericValue =\n typeof value === 'bigint' ? Number(value) : (value as number)\n const rule = formatters\n .getPluralRules(locales, {type: el.pluralType})\n .select(numericValue - (el.offset || 0))\n opt =\n (Object.prototype.hasOwnProperty.call(el.options, rule)\n ? el.options[rule]\n : undefined) || el.options.other\n }\n if (!opt) {\n throw new InvalidValueError(\n el.value,\n value,\n Object.keys(el.options),\n originalMessage\n )\n }\n // Convert bigint to number for currentPluralValue\n const numericValue =\n typeof value === 'bigint' ? Number(value) : (value as number)\n result.push(\n ...formatToParts(\n opt.value,\n locales,\n formatters,\n formats,\n values,\n numericValue - (el.offset || 0)\n )\n )\n continue\n }\n }\n return mergeLiteral(result)\n}\n\nexport type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (\n parts: Array<string | T>\n) => R\n","/*\nCopyright (c) 2014, Yahoo! Inc. All rights reserved.\nCopyrights licensed under the New BSD License.\nSee the accompanying LICENSE file for terms.\n*/\n\nimport {type Cache, memoize, strategies} from '@formatjs/fast-memoize'\nimport {\n type MessageFormatElement,\n parse,\n type ParserOptions,\n} from '@formatjs/icu-messageformat-parser'\nimport {\n type Formats,\n type FormatterCache,\n type Formatters,\n formatToParts,\n type FormatXMLElementFn,\n type MessageFormatPart,\n PART_TYPE,\n type PrimitiveType,\n} from '#packages/intl-messageformat/formatters.js'\n\n// -- MessageFormat --------------------------------------------------------\n\nfunction mergeConfig(c1: Record<string, object>, c2?: Record<string, object>) {\n if (!c2) {\n return c1\n }\n return {\n ...c1,\n ...c2,\n ...Object.keys(c1).reduce((all: Record<string, object>, k) => {\n all[k] = {\n ...c1[k],\n ...c2[k],\n }\n return all\n }, {}),\n }\n}\n\nfunction mergeConfigs(\n defaultConfig: Formats,\n configs?: Partial<Formats>\n): Formats {\n if (!configs) {\n return defaultConfig\n }\n\n return (Object.keys(defaultConfig) as Array<keyof Formats>).reduce(\n (all: Formats, k: keyof Formats) => {\n all[k] = mergeConfig(defaultConfig[k], configs[k])\n return all\n },\n {...defaultConfig}\n )\n}\n\nexport interface Options extends Omit<ParserOptions, 'locale'> {\n formatters?: Formatters\n}\n\nfunction createFastMemoizeCache<V>(\n store: Record<string, V | undefined>\n): Cache<string, V> {\n return {\n create() {\n return {\n get(key) {\n return store[key]\n },\n set(key, value) {\n store[key] = value\n },\n }\n },\n }\n}\n\nfunction createDefaultFormatters(\n cache: FormatterCache = {\n number: {},\n dateTime: {},\n pluralRules: {},\n }\n): Formatters {\n return {\n getNumberFormat: memoize((...args) => new Intl.NumberFormat(...args), {\n cache: createFastMemoizeCache(cache.number),\n strategy: strategies.variadic,\n }),\n getDateTimeFormat: memoize((...args) => new Intl.DateTimeFormat(...args), {\n cache: createFastMemoizeCache(cache.dateTime),\n strategy: strategies.variadic,\n }),\n getPluralRules: memoize((...args) => new Intl.PluralRules(...args), {\n cache: createFastMemoizeCache(cache.pluralRules),\n strategy: strategies.variadic,\n }),\n }\n}\n\nexport class IntlMessageFormat {\n private readonly ast: MessageFormatElement[]\n private readonly locales: string | string[]\n private readonly resolvedLocale?: Intl.Locale\n private readonly formatters: Formatters\n private readonly formats: Formats\n private readonly message: string | undefined\n private readonly formatterCache: FormatterCache = {\n number: {},\n dateTime: {},\n pluralRules: {},\n }\n constructor(\n message: string | MessageFormatElement[],\n locales: string | string[] = IntlMessageFormat.defaultLocale,\n overrideFormats?: Partial<Formats>,\n opts?: Options\n ) {\n // Defined first because it's used to build the format pattern.\n this.locales = locales\n this.resolvedLocale = IntlMessageFormat.resolveLocale(locales)\n\n if (typeof message === 'string') {\n this.message = message\n if (!IntlMessageFormat.__parse) {\n throw new TypeError(\n 'IntlMessageFormat.__parse must be set to process `message` of type `string`'\n )\n }\n const {...parseOpts} = opts || {}\n // Parse string messages into an AST.\n this.ast = IntlMessageFormat.__parse(message, {\n ...parseOpts,\n locale: this.resolvedLocale,\n })\n } else {\n this.ast = message\n }\n\n if (!Array.isArray(this.ast)) {\n throw new TypeError('A message must be provided as a String or AST.')\n }\n\n // Creates a new object with the specified `formats` merged with the default\n // formats.\n this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats)\n\n this.formatters =\n (opts && opts.formatters) || createDefaultFormatters(this.formatterCache)\n }\n\n format = <T = void>(\n values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>\n ): string | T | (string | T)[] => {\n const parts = this.formatToParts(values)\n // Hot path for straight simple msg translations\n if (parts.length === 1) {\n return parts[0].value\n }\n const result = parts.reduce(\n (all, part) => {\n if (\n !all.length ||\n part.type !== PART_TYPE.literal ||\n typeof all[all.length - 1] !== 'string'\n ) {\n all.push(part.value)\n } else {\n all[all.length - 1] += part.value\n }\n return all\n },\n [] as Array<string | T>\n )\n\n if (result.length <= 1) {\n return result[0] || ''\n }\n return result\n }\n formatToParts = <T>(\n values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>\n ): MessageFormatPart<T>[] =>\n formatToParts(\n this.ast,\n this.locales,\n this.formatters,\n this.formats,\n values,\n undefined,\n this.message\n )\n resolvedOptions = (): {\n locale: string\n } => ({\n locale:\n this.resolvedLocale?.toString() ||\n Intl.NumberFormat.supportedLocalesOf(this.locales)[0],\n })\n getAst = (): MessageFormatElement[] => this.ast\n private static memoizedDefaultLocale: string | null = null\n\n static get defaultLocale(): string {\n if (!IntlMessageFormat.memoizedDefaultLocale) {\n IntlMessageFormat.memoizedDefaultLocale =\n new Intl.NumberFormat().resolvedOptions().locale\n }\n\n return IntlMessageFormat.memoizedDefaultLocale\n }\n static resolveLocale = (\n locales: string | string[]\n ): Intl.Locale | undefined => {\n if (typeof Intl.Locale === 'undefined') {\n return\n }\n const supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales)\n if (supportedLocales.length > 0) {\n return new Intl.Locale(supportedLocales[0])\n }\n\n return new Intl.Locale(typeof locales === 'string' ? locales : locales[0])\n }\n static __parse: typeof parse | undefined = parse\n // Default format options used as the prototype of the `formats` provided to the\n // constructor. These are used when constructing the internal Intl.NumberFormat\n // and Intl.DateTimeFormat instances.\n static formats: Formats = {\n number: {\n integer: {\n maximumFractionDigits: 0,\n },\n currency: {\n style: 'currency',\n },\n\n percent: {\n style: 'percent',\n },\n },\n\n date: {\n short: {\n month: 'numeric',\n day: 'numeric',\n year: '2-digit',\n },\n\n medium: {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n },\n\n long: {\n month: 'long',\n day: 'numeric',\n year: 'numeric',\n },\n\n full: {\n weekday: 'long',\n month: 'long',\n day: 'numeric',\n year: 'numeric',\n },\n },\n\n time: {\n short: {\n hour: 'numeric',\n minute: 'numeric',\n },\n\n medium: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n },\n\n long: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n timeZoneName: 'short',\n },\n\n full: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n timeZoneName: 'short',\n },\n },\n }\n}\n","/*\nCopyright (c) 2014, Yahoo! Inc. All rights reserved.\nCopyrights licensed under the New BSD License.\nSee the accompanying LICENSE file for terms.\n*/\n\nimport {IntlMessageFormat} from '#packages/intl-messageformat/core.js'\nexport * from '#packages/intl-messageformat/core.js'\nexport * from '#packages/intl-messageformat/error.js'\nexport * from '#packages/intl-messageformat/formatters.js'\nexport {IntlMessageFormat}\nexport default IntlMessageFormat\n"],"mappings":";;;AAAA,IAAY,YAAL,yBAAA,WAAA;AAEL,WAAA,mBAAA;AAEA,WAAA,mBAAA;AAEA,WAAA,sBAAA;;KACD;AAED,IAAa,cAAb,cAAiC,MAAM;CAUrC,YAAY,KAAa,MAAiB,iBAA0B;AAClE,QAAM,IAAI;AACV,OAAK,OAAO;AACZ,OAAK,kBAAkB;;CAEzB,WAAkB;AAChB,SAAO,oBAAoB,KAAK,KAAK,IAAI,KAAK;;;AAIlD,IAAa,oBAAb,cAAuC,YAAY;CACjD,YACE,YACA,OACA,SACA,iBACA;AACA,QACE,uBAAuB,WAAW,MAAM,MAAM,kBAAkB,OAAO,KACrE,QACD,CAAC,KAAK,SAAO,CAAC,IACf,UAAU,eACV,gBACD;;;AAIL,IAAa,wBAAb,cAA2C,YAAY;CACrD,YAAY,OAAY,MAAc,iBAA0B;AAC9D,QACE,cAAc,MAAM,oBAAoB,QACxC,UAAU,eACV,gBACD;;;AAIL,IAAa,oBAAb,cAAuC,YAAY;CACjD,YAAY,YAAoB,iBAA0B;AACxD,QACE,qCAAqC,WAAW,oCAAoC,gBAAgB,IACpG,UAAU,eACV,gBACD;;;;;ACDL,IAAY,YAAL,yBAAA,WAAA;AACL,WAAA,UAAA,aAAA,KAAA;AACA,WAAA,UAAA,YAAA,KAAA;;KACD;AAuBD,SAAS,aACP,OACwB;AACxB,KAAI,MAAM,SAAS,EACjB,QAAO;AAET,QAAO,MAAM,QAAQ,KAAK,SAAS;EACjC,MAAM,WAAW,IAAI,IAAI,SAAS;AAClC,MACE,CAAC,YACD,SAAS,SAAS,UAAU,WAC5B,KAAK,SAAS,UAAU,QAExB,KAAI,KAAK,KAAK;MAEd,UAAS,SAAS,KAAK;AAEzB,SAAO;IACN,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AC5B,QAAO,IAAI,KAAK,OAAO,iBAAiB,GAAG;AAG7C,UAAO,IAAI,KAAK,OAAO,OAAO,YAAY,WAAW,UAAU,QAAQ,GAAG;;;;iBAEjC;;;iBAIjB;GACxB,QAAQ;IACN,SAAS,EACP,uBAAuB,GACxB;IACD,UAAU,EACR,OAAO,YACR;IAED,SAAS,EACP,OAAO,WACR;IACF;GAED,MAAM;IACJ,OAAO;KACL,OAAO;KACP,KAAK;KACL,MAAM;KACP;IAED,QAAQ;KACN,OAAO;KACP,KAAK;KACL,MAAM;KACP;IAED,MAAM;KACJ,OAAO;KACP,KAAK;KACL,MAAM;KACP;IAED,MAAM;KACJ,SAAS;KACT,OAAO;KACP,KAAK;KACL,MAAM;KACP;IACF;GAED,MAAM;IACJ,OAAO;KACL,MAAM;KACN,QAAQ;KACT;IAED,QAAQ;KACN,MAAM;KACN,QAAQ;KACR,QAAQ;KACT;IAED,MAAM;KACJ,MAAM;KACN,QAAQ;KACR,QAAQ;KACR,cAAc;KACf;IAED,MAAM;KACJ,MAAM;KACN,QAAQ;KACR,QAAQ;KACR,cAAc;KACf;IACF;GACF;;;;;AC9RH,IAAA,6BAAe"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../error.ts","../formatters.ts","../core.ts","../index.ts"],"sourcesContent":["export enum ErrorCode {\n // When we have a placeholder but no value to format\n MISSING_VALUE = 'MISSING_VALUE',\n // When value supplied is invalid\n INVALID_VALUE = 'INVALID_VALUE',\n // When we need specific Intl API but it's not available\n MISSING_INTL_API = 'MISSING_INTL_API',\n}\n\nexport class FormatError extends Error {\n public readonly code: ErrorCode\n /**\n * Original message we're trying to format\n * `undefined` if we're only dealing w/ AST\n *\n * @type {(string | undefined)}\n * @memberof FormatError\n */\n public readonly originalMessage: string | undefined\n constructor(msg: string, code: ErrorCode, originalMessage?: string) {\n super(msg)\n this.code = code\n this.originalMessage = originalMessage\n }\n public toString() {\n return `[formatjs Error: ${this.code}] ${this.message}`\n }\n}\n\nexport class InvalidValueError extends FormatError {\n constructor(\n variableId: string,\n value: any,\n options: string[],\n originalMessage?: string\n ) {\n super(\n `Invalid values for \"${variableId}\": \"${value}\". Options are \"${Object.keys(\n options\n ).join('\", \"')}\"`,\n ErrorCode.INVALID_VALUE,\n originalMessage\n )\n }\n}\n\nexport class InvalidValueTypeError extends FormatError {\n constructor(value: any, type: string, originalMessage?: string) {\n super(\n `Value for \"${value}\" must be of type ${type}`,\n ErrorCode.INVALID_VALUE,\n originalMessage\n )\n }\n}\n\nexport class MissingValueError extends FormatError {\n constructor(variableId: string, originalMessage?: string) {\n super(\n `The intl string context variable \"${variableId}\" was not provided to the string \"${originalMessage}\"`,\n ErrorCode.MISSING_VALUE,\n originalMessage\n )\n }\n}\n","import {type NumberFormatOptions} from '#packages/ecma402-abstract/types/number.js'\nimport {\n type ExtendedNumberFormatOptions,\n isArgumentElement,\n isDateElement,\n isDateTimeSkeleton,\n isLiteralElement,\n isNumberElement,\n isNumberSkeleton,\n isPluralElement,\n isPoundElement,\n isSelectElement,\n isTagElement,\n isTimeElement,\n type MessageFormatElement,\n} from '@formatjs/icu-messageformat-parser'\nimport {\n ErrorCode,\n FormatError,\n InvalidValueError,\n InvalidValueTypeError,\n MissingValueError,\n} from '#packages/intl-messageformat/error.js'\n\ndeclare global {\n namespace FormatjsIntl {\n interface Message {}\n interface IntlConfig {}\n interface Formats {}\n }\n}\n\ntype Format<Source = string> = Source extends keyof FormatjsIntl.Formats\n ? FormatjsIntl.Formats[Source]\n : string\n\nexport interface Formats {\n number: Record<Format<'number'>, NumberFormatOptions>\n date: Record<Format<'date'>, Intl.DateTimeFormatOptions>\n time: Record<Format<'time'>, Intl.DateTimeFormatOptions>\n}\n\nexport interface FormatterCache {\n number: Record<string, NumberFormatOptions>\n dateTime: Record<string, Intl.DateTimeFormat>\n pluralRules: Record<string, Intl.PluralRules>\n}\n\nexport interface Formatters {\n getNumberFormat(\n locals?: string | string[],\n opts?: NumberFormatOptions\n ): Intl.NumberFormat\n getDateTimeFormat(\n ...args: ConstructorParameters<typeof Intl.DateTimeFormat>\n ): Intl.DateTimeFormat\n getPluralRules(\n ...args: ConstructorParameters<typeof Intl.PluralRules>\n ): Intl.PluralRules\n}\n\nexport enum PART_TYPE {\n literal,\n object,\n}\n\nexport interface LiteralPart {\n type: PART_TYPE.literal\n value: string\n}\n\nexport interface ObjectPart<T = any> {\n type: PART_TYPE.object\n value: T\n}\n\nexport type MessageFormatPart<T> = LiteralPart | ObjectPart<T>\n\nexport type PrimitiveType =\n | string\n | number\n | bigint\n | boolean\n | null\n | undefined\n | Date\n\nfunction mergeLiteral<T>(\n parts: MessageFormatPart<T>[]\n): MessageFormatPart<T>[] {\n if (parts.length < 2) {\n return parts\n }\n return parts.reduce((all, part) => {\n const lastPart = all[all.length - 1]\n if (\n !lastPart ||\n lastPart.type !== PART_TYPE.literal ||\n part.type !== PART_TYPE.literal\n ) {\n all.push(part)\n } else {\n lastPart.value += part.value\n }\n return all\n }, [] as MessageFormatPart<T>[])\n}\n\nexport function isFormatXMLElementFn<T>(\n el: PrimitiveType | T | FormatXMLElementFn<T>\n): el is FormatXMLElementFn<T> {\n return typeof el === 'function'\n}\n\n// TODO(skeleton): add skeleton support\nexport function formatToParts<T>(\n els: MessageFormatElement[],\n locales: string | string[],\n formatters: Formatters,\n formats: Formats,\n values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>,\n currentPluralValue?: number,\n // For debugging\n originalMessage?: string\n): MessageFormatPart<T>[] {\n // Hot path for straight simple msg translations\n if (els.length === 1 && isLiteralElement(els[0])) {\n return [\n {\n type: PART_TYPE.literal,\n value: els[0].value,\n },\n ]\n }\n const result: MessageFormatPart<T>[] = []\n for (const el of els) {\n // Exit early for string parts.\n if (isLiteralElement(el)) {\n result.push({\n type: PART_TYPE.literal,\n value: el.value,\n })\n continue\n }\n // TODO: should this part be literal type?\n // Replace `#` in plural rules with the actual numeric value.\n if (isPoundElement(el)) {\n if (typeof currentPluralValue === 'number') {\n result.push({\n type: PART_TYPE.literal,\n value: formatters.getNumberFormat(locales).format(currentPluralValue),\n })\n }\n continue\n }\n\n const {value: varName} = el\n\n // Enforce that all required values are provided by the caller.\n if (!(values && varName in values)) {\n throw new MissingValueError(varName, originalMessage)\n }\n\n let value = values[varName]\n if (isArgumentElement(el)) {\n if (\n !value ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'bigint'\n ) {\n value =\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'bigint'\n ? String(value)\n : ''\n }\n result.push({\n type: typeof value === 'string' ? PART_TYPE.literal : PART_TYPE.object,\n value,\n } as ObjectPart<T>)\n continue\n }\n\n // Recursively format plural and select parts' option — which can be a\n // nested pattern structure. The choosing of the option to use is\n // abstracted-by and delegated-to the part helper object.\n if (isDateElement(el)) {\n const style =\n typeof el.style === 'string'\n ? formats.date[el.style]\n : isDateTimeSkeleton(el.style)\n ? el.style.parsedOptions\n : undefined\n result.push({\n type: PART_TYPE.literal,\n value: formatters\n .getDateTimeFormat(locales, style)\n .format(value as number),\n })\n continue\n }\n if (isTimeElement(el)) {\n const style =\n typeof el.style === 'string'\n ? formats.time[el.style]\n : isDateTimeSkeleton(el.style)\n ? el.style.parsedOptions\n : formats.time.medium\n result.push({\n type: PART_TYPE.literal,\n value: formatters\n .getDateTimeFormat(locales, style)\n .format(value as number),\n })\n continue\n }\n if (isNumberElement(el)) {\n const style =\n typeof el.style === 'string'\n ? formats.number[el.style]\n : isNumberSkeleton(el.style)\n ? el.style.parsedOptions\n : undefined\n\n if (style && (style as ExtendedNumberFormatOptions).scale) {\n const scale = (style as ExtendedNumberFormatOptions).scale || 1\n // Handle bigint scale multiplication\n // BigInt can only be multiplied by BigInt\n if (typeof value === 'bigint') {\n // Check if scale is a safe integer that can be converted to BigInt\n if (!Number.isInteger(scale)) {\n throw new TypeError(\n `Cannot apply fractional scale ${scale} to bigint value. Scale must be an integer when formatting bigint.`\n )\n }\n value = value * BigInt(scale)\n } else {\n value = (value as number) * scale\n }\n }\n result.push({\n type: PART_TYPE.literal,\n value: formatters\n .getNumberFormat(locales, style)\n .format(value as number | bigint),\n })\n continue\n }\n if (isTagElement(el)) {\n const {children, value} = el\n const formatFn = values[value]\n if (!isFormatXMLElementFn<T>(formatFn)) {\n throw new InvalidValueTypeError(value, 'function', originalMessage)\n }\n const parts = formatToParts<T>(\n children,\n locales,\n formatters,\n formats,\n values,\n currentPluralValue\n )\n let chunks = formatFn(parts.map(p => p.value))\n if (!Array.isArray(chunks)) {\n chunks = [chunks]\n }\n result.push(\n ...chunks.map((c): MessageFormatPart<T> => {\n return {\n type: typeof c === 'string' ? PART_TYPE.literal : PART_TYPE.object,\n value: c,\n } as MessageFormatPart<T>\n })\n )\n }\n if (isSelectElement(el)) {\n // GH #4490: Use hasOwnProperty to avoid prototype chain issues with keys like \"constructor\"\n const key = value as string\n const opt =\n (Object.prototype.hasOwnProperty.call(el.options, key)\n ? el.options[key]\n : undefined) || el.options.other\n if (!opt) {\n throw new InvalidValueError(\n el.value,\n value,\n Object.keys(el.options),\n originalMessage\n )\n }\n result.push(\n ...formatToParts(opt.value, locales, formatters, formats, values)\n )\n continue\n }\n if (isPluralElement(el)) {\n // GH #4490: Use hasOwnProperty to avoid prototype chain issues\n const exactKey = `=${value}`\n let opt = Object.prototype.hasOwnProperty.call(el.options, exactKey)\n ? el.options[exactKey]\n : undefined\n if (!opt) {\n if (!Intl.PluralRules) {\n throw new FormatError(\n `Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n`,\n ErrorCode.MISSING_INTL_API,\n originalMessage\n )\n }\n // Convert bigint to number for PluralRules (which only accepts number)\n const numericValue =\n typeof value === 'bigint' ? Number(value) : (value as number)\n const rule = formatters\n .getPluralRules(locales, {type: el.pluralType})\n .select(numericValue - (el.offset || 0))\n opt =\n (Object.prototype.hasOwnProperty.call(el.options, rule)\n ? el.options[rule]\n : undefined) || el.options.other\n }\n if (!opt) {\n throw new InvalidValueError(\n el.value,\n value,\n Object.keys(el.options),\n originalMessage\n )\n }\n // Convert bigint to number for currentPluralValue\n const numericValue =\n typeof value === 'bigint' ? Number(value) : (value as number)\n result.push(\n ...formatToParts(\n opt.value,\n locales,\n formatters,\n formats,\n values,\n numericValue - (el.offset || 0)\n )\n )\n continue\n }\n }\n return mergeLiteral(result)\n}\n\nexport type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (\n parts: Array<string | T>\n) => R\n","/*\nCopyright (c) 2014, Yahoo! Inc. All rights reserved.\nCopyrights licensed under the New BSD License.\nSee the accompanying LICENSE file for terms.\n*/\n\nimport {type Cache, memoize, strategies} from '@formatjs/fast-memoize'\nimport {\n type MessageFormatElement,\n parse,\n type ParserOptions,\n} from '@formatjs/icu-messageformat-parser'\nimport {\n type Formats,\n type FormatterCache,\n type Formatters,\n formatToParts,\n type FormatXMLElementFn,\n type MessageFormatPart,\n PART_TYPE,\n type PrimitiveType,\n} from '#packages/intl-messageformat/formatters.js'\n\n// -- MessageFormat --------------------------------------------------------\n\nfunction mergeConfig(c1: Record<string, object>, c2?: Record<string, object>) {\n if (!c2) {\n return c1\n }\n return {\n ...c1,\n ...c2,\n ...Object.keys(c1).reduce((all: Record<string, object>, k) => {\n all[k] = {\n ...c1[k],\n ...c2[k],\n }\n return all\n }, {}),\n }\n}\n\nfunction mergeConfigs(\n defaultConfig: Formats,\n configs?: Partial<Formats>\n): Formats {\n if (!configs) {\n return defaultConfig\n }\n\n return (Object.keys(defaultConfig) as Array<keyof Formats>).reduce(\n (all: Formats, k: keyof Formats) => {\n all[k] = mergeConfig(defaultConfig[k], configs[k])\n return all\n },\n {...defaultConfig}\n )\n}\n\nexport interface Options extends Omit<ParserOptions, 'locale'> {\n formatters?: Formatters\n}\n\nfunction createFastMemoizeCache<V>(\n store: Record<string, V | undefined>\n): Cache<string, V> {\n return {\n create() {\n return {\n get(key) {\n return store[key]\n },\n set(key, value) {\n store[key] = value\n },\n }\n },\n }\n}\n\nfunction createDefaultFormatters(\n cache: FormatterCache = {\n number: {},\n dateTime: {},\n pluralRules: {},\n }\n): Formatters {\n return {\n getNumberFormat: memoize((...args) => new Intl.NumberFormat(...args), {\n cache: createFastMemoizeCache(cache.number),\n strategy: strategies.variadic,\n }),\n getDateTimeFormat: memoize((...args) => new Intl.DateTimeFormat(...args), {\n cache: createFastMemoizeCache(cache.dateTime),\n strategy: strategies.variadic,\n }),\n getPluralRules: memoize((...args) => new Intl.PluralRules(...args), {\n cache: createFastMemoizeCache(cache.pluralRules),\n strategy: strategies.variadic,\n }),\n }\n}\n\nexport class IntlMessageFormat {\n private readonly ast: MessageFormatElement[]\n private readonly locales: string | string[]\n private readonly resolvedLocale?: Intl.Locale\n private readonly formatters: Formatters\n private readonly formats: Formats\n private readonly message: string | undefined\n private readonly formatterCache: FormatterCache = {\n number: {},\n dateTime: {},\n pluralRules: {},\n }\n constructor(\n message: string | MessageFormatElement[],\n locales: string | string[] = IntlMessageFormat.defaultLocale,\n overrideFormats?: Partial<Formats>,\n opts?: Options\n ) {\n // Defined first because it's used to build the format pattern.\n this.locales = locales\n this.resolvedLocale = IntlMessageFormat.resolveLocale(locales)\n\n if (typeof message === 'string') {\n this.message = message\n if (!IntlMessageFormat.__parse) {\n throw new TypeError(\n 'IntlMessageFormat.__parse must be set to process `message` of type `string`'\n )\n }\n const {...parseOpts} = opts || {}\n // Parse string messages into an AST.\n this.ast = IntlMessageFormat.__parse(message, {\n ...parseOpts,\n locale: this.resolvedLocale,\n })\n } else {\n this.ast = message\n }\n\n if (!Array.isArray(this.ast)) {\n throw new TypeError('A message must be provided as a String or AST.')\n }\n\n // Creates a new object with the specified `formats` merged with the default\n // formats.\n this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats)\n\n this.formatters =\n (opts && opts.formatters) || createDefaultFormatters(this.formatterCache)\n }\n\n format = <T = void>(\n values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>\n ): string | T | (string | T)[] => {\n const parts = this.formatToParts(values)\n // Hot path for straight simple msg translations\n if (parts.length === 1) {\n return parts[0].value\n }\n const result = parts.reduce(\n (all, part) => {\n if (\n !all.length ||\n part.type !== PART_TYPE.literal ||\n typeof all[all.length - 1] !== 'string'\n ) {\n all.push(part.value)\n } else {\n all[all.length - 1] += part.value\n }\n return all\n },\n [] as Array<string | T>\n )\n\n if (result.length <= 1) {\n return result[0] || ''\n }\n return result\n }\n formatToParts = <T>(\n values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>\n ): MessageFormatPart<T>[] =>\n formatToParts(\n this.ast,\n this.locales,\n this.formatters,\n this.formats,\n values,\n undefined,\n this.message\n )\n resolvedOptions = (): {\n locale: string\n } => ({\n locale:\n this.resolvedLocale?.toString() ||\n Intl.NumberFormat.supportedLocalesOf(this.locales)[0],\n })\n getAst = (): MessageFormatElement[] => this.ast\n private static memoizedDefaultLocale: string | null = null\n\n static get defaultLocale(): string {\n if (!IntlMessageFormat.memoizedDefaultLocale) {\n IntlMessageFormat.memoizedDefaultLocale =\n new Intl.NumberFormat().resolvedOptions().locale\n }\n\n return IntlMessageFormat.memoizedDefaultLocale\n }\n static resolveLocale = (\n locales: string | string[]\n ): Intl.Locale | undefined => {\n if (typeof Intl.Locale === 'undefined') {\n return\n }\n const supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales)\n if (supportedLocales.length > 0) {\n return new Intl.Locale(supportedLocales[0])\n }\n\n return new Intl.Locale(typeof locales === 'string' ? locales : locales[0])\n }\n static __parse: typeof parse | undefined = parse\n // Default format options used as the prototype of the `formats` provided to the\n // constructor. These are used when constructing the internal Intl.NumberFormat\n // and Intl.DateTimeFormat instances.\n static formats: Formats = {\n number: {\n integer: {\n maximumFractionDigits: 0,\n },\n currency: {\n style: 'currency',\n },\n\n percent: {\n style: 'percent',\n },\n },\n\n date: {\n short: {\n month: 'numeric',\n day: 'numeric',\n year: '2-digit',\n },\n\n medium: {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n },\n\n long: {\n month: 'long',\n day: 'numeric',\n year: 'numeric',\n },\n\n full: {\n weekday: 'long',\n month: 'long',\n day: 'numeric',\n year: 'numeric',\n },\n },\n\n time: {\n short: {\n hour: 'numeric',\n minute: 'numeric',\n },\n\n medium: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n },\n\n long: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n timeZoneName: 'short',\n },\n\n full: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n timeZoneName: 'short',\n },\n },\n }\n}\n","/*\nCopyright (c) 2014, Yahoo! Inc. All rights reserved.\nCopyrights licensed under the New BSD License.\nSee the accompanying LICENSE file for terms.\n*/\n\nimport {IntlMessageFormat} from '#packages/intl-messageformat/core.js'\nexport * from '#packages/intl-messageformat/core.js'\nexport * from '#packages/intl-messageformat/error.js'\nexport * from '#packages/intl-messageformat/formatters.js'\nexport {IntlMessageFormat}\nexport default IntlMessageFormat\n"],"mappings":";;;AAAA,IAAY,YAAL,yBAAA,WAAA;CAEL,UAAA,mBAAA;CAEA,UAAA,mBAAA;CAEA,UAAA,sBAAA;;AACF,EAAA,CAAA,CAAA;AAEA,IAAa,cAAb,cAAiC,MAAM;CAUrC,YAAY,KAAa,MAAiB,iBAA0B;EAClE,MAAM,GAAG;EACT,KAAK,OAAO;EACZ,KAAK,kBAAkB;CACzB;CACA,WAAkB;EAChB,OAAO,oBAAoB,KAAK,KAAK,IAAI,KAAK;CAChD;AACF;AAEA,IAAa,oBAAb,cAAuC,YAAY;CACjD,YACE,YACA,OACA,SACA,iBACA;EACA,MACE,uBAAuB,WAAW,MAAM,MAAM,kBAAkB,OAAO,KACrE,OACF,EAAE,KAAK,QAAM,EAAE,IAAA,iBAEf,eACF;CACF;AACF;AAEA,IAAa,wBAAb,cAA2C,YAAY;CACrD,YAAY,OAAY,MAAc,iBAA0B;EAC9D,MACE,cAAc,MAAM,oBAAoB,QAAA,iBAExC,eACF;CACF;AACF;AAEA,IAAa,oBAAb,cAAuC,YAAY;C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501,86 +501,41 @@ let ErrorKind = /* @__PURE__ */ function(ErrorKind) {
|
|
|
501
501
|
ErrorKind[ErrorKind["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG";
|
|
502
502
|
return ErrorKind;
|
|
503
503
|
}({});
|
|
504
|
-
let TYPE = /* @__PURE__ */ function(TYPE) {
|
|
505
|
-
/**
|
|
506
|
-
* Raw text
|
|
507
|
-
*/
|
|
508
|
-
TYPE[TYPE["literal"] = 0] = "literal";
|
|
509
|
-
/**
|
|
510
|
-
* Variable w/o any format, e.g `var` in `this is a {var}`
|
|
511
|
-
*/
|
|
512
|
-
TYPE[TYPE["argument"] = 1] = "argument";
|
|
513
|
-
/**
|
|
514
|
-
* Variable w/ number format
|
|
515
|
-
*/
|
|
516
|
-
TYPE[TYPE["number"] = 2] = "number";
|
|
517
|
-
/**
|
|
518
|
-
* Variable w/ date format
|
|
519
|
-
*/
|
|
520
|
-
TYPE[TYPE["date"] = 3] = "date";
|
|
521
|
-
/**
|
|
522
|
-
* Variable w/ time format
|
|
523
|
-
*/
|
|
524
|
-
TYPE[TYPE["time"] = 4] = "time";
|
|
525
|
-
/**
|
|
526
|
-
* Variable w/ select format
|
|
527
|
-
*/
|
|
528
|
-
TYPE[TYPE["select"] = 5] = "select";
|
|
529
|
-
/**
|
|
530
|
-
* Variable w/ plural format
|
|
531
|
-
*/
|
|
532
|
-
TYPE[TYPE["plural"] = 6] = "plural";
|
|
533
|
-
/**
|
|
534
|
-
* Only possible within plural argument.
|
|
535
|
-
* This is the `#` symbol that will be substituted with the count.
|
|
536
|
-
*/
|
|
537
|
-
TYPE[TYPE["pound"] = 7] = "pound";
|
|
538
|
-
/**
|
|
539
|
-
* XML-like tag
|
|
540
|
-
*/
|
|
541
|
-
TYPE[TYPE["tag"] = 8] = "tag";
|
|
542
|
-
return TYPE;
|
|
543
|
-
}({});
|
|
544
|
-
let SKELETON_TYPE = /* @__PURE__ */ function(SKELETON_TYPE) {
|
|
545
|
-
SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
|
|
546
|
-
SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
|
|
547
|
-
return SKELETON_TYPE;
|
|
548
|
-
}({});
|
|
549
504
|
/**
|
|
550
505
|
* Type Guards
|
|
551
506
|
*/
|
|
552
507
|
function isLiteralElement(el) {
|
|
553
|
-
return el.type ===
|
|
508
|
+
return el.type === 0;
|
|
554
509
|
}
|
|
555
510
|
function isArgumentElement(el) {
|
|
556
|
-
return el.type ===
|
|
511
|
+
return el.type === 1;
|
|
557
512
|
}
|
|
558
513
|
function isNumberElement(el) {
|
|
559
|
-
return el.type ===
|
|
514
|
+
return el.type === 2;
|
|
560
515
|
}
|
|
561
516
|
function isDateElement(el) {
|
|
562
|
-
return el.type ===
|
|
517
|
+
return el.type === 3;
|
|
563
518
|
}
|
|
564
519
|
function isTimeElement(el) {
|
|
565
|
-
return el.type ===
|
|
520
|
+
return el.type === 4;
|
|
566
521
|
}
|
|
567
522
|
function isSelectElement(el) {
|
|
568
|
-
return el.type ===
|
|
523
|
+
return el.type === 5;
|
|
569
524
|
}
|
|
570
525
|
function isPluralElement(el) {
|
|
571
|
-
return el.type ===
|
|
526
|
+
return el.type === 6;
|
|
572
527
|
}
|
|
573
528
|
function isPoundElement(el) {
|
|
574
|
-
return el.type ===
|
|
529
|
+
return el.type === 7;
|
|
575
530
|
}
|
|
576
531
|
function isTagElement(el) {
|
|
577
|
-
return el.type ===
|
|
532
|
+
return el.type === 8;
|
|
578
533
|
}
|
|
579
534
|
function isNumberSkeleton(el) {
|
|
580
|
-
return !!(el && typeof el === "object" && el.type ===
|
|
535
|
+
return !!(el && typeof el === "object" && el.type === 0);
|
|
581
536
|
}
|
|
582
537
|
function isDateTimeSkeleton(el) {
|
|
583
|
-
return !!(el && typeof el === "object" && el.type ===
|
|
538
|
+
return !!(el && typeof el === "object" && el.type === 1);
|
|
584
539
|
}
|
|
585
540
|
const SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/;
|
|
586
541
|
const timeData = {
|
|
@@ -1826,6 +1781,37 @@ function matchIdentifierAtIndex(s, index) {
|
|
|
1826
1781
|
IDENTIFIER_PREFIX_RE.lastIndex = index;
|
|
1827
1782
|
return IDENTIFIER_PREFIX_RE.exec(s)[1] ?? "";
|
|
1828
1783
|
}
|
|
1784
|
+
function plainTopLevelEndPosition(message) {
|
|
1785
|
+
if (message.length === 0) return null;
|
|
1786
|
+
let line = 1;
|
|
1787
|
+
let column = 1;
|
|
1788
|
+
for (let offset = 0; offset < message.length;) {
|
|
1789
|
+
const code = message.charCodeAt(offset);
|
|
1790
|
+
switch (code) {
|
|
1791
|
+
case 35:
|
|
1792
|
+
case 39:
|
|
1793
|
+
case 60:
|
|
1794
|
+
case 123:
|
|
1795
|
+
case 125: return null;
|
|
1796
|
+
}
|
|
1797
|
+
if (code === 10) {
|
|
1798
|
+
line++;
|
|
1799
|
+
column = 1;
|
|
1800
|
+
offset++;
|
|
1801
|
+
} else {
|
|
1802
|
+
column++;
|
|
1803
|
+
if (code >= 55296 && code <= 56319 && offset + 1 < message.length) {
|
|
1804
|
+
const next = message.charCodeAt(offset + 1);
|
|
1805
|
+
offset += next >= 56320 && next <= 57343 ? 2 : 1;
|
|
1806
|
+
} else offset++;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
return {
|
|
1810
|
+
offset: message.length,
|
|
1811
|
+
line,
|
|
1812
|
+
column
|
|
1813
|
+
};
|
|
1814
|
+
}
|
|
1829
1815
|
var Parser = class {
|
|
1830
1816
|
constructor(message, options = {}) {
|
|
1831
1817
|
this.message = message;
|
|
@@ -1841,6 +1827,24 @@ var Parser = class {
|
|
|
1841
1827
|
}
|
|
1842
1828
|
parse() {
|
|
1843
1829
|
if (this.offset() !== 0) throw Error("parser can only be used once");
|
|
1830
|
+
if (this.message.length > 0) {
|
|
1831
|
+
const firstCode = this.message.charCodeAt(0);
|
|
1832
|
+
if (firstCode !== 35 && firstCode !== 39 && firstCode !== 60 && firstCode !== 123 && firstCode !== 125) {
|
|
1833
|
+
const plainEndPosition = plainTopLevelEndPosition(this.message);
|
|
1834
|
+
if (plainEndPosition) {
|
|
1835
|
+
const start = this.clonePosition();
|
|
1836
|
+
this.position = plainEndPosition;
|
|
1837
|
+
return {
|
|
1838
|
+
val: [{
|
|
1839
|
+
type: 0,
|
|
1840
|
+
value: this.message,
|
|
1841
|
+
location: createLocation(start, this.clonePosition())
|
|
1842
|
+
}],
|
|
1843
|
+
err: null
|
|
1844
|
+
};
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1844
1848
|
return this.parseMessage(0, "", false);
|
|
1845
1849
|
}
|
|
1846
1850
|
parseMessage(nestingLevel, parentArgType, expectingCloseTag) {
|
|
@@ -1856,11 +1860,11 @@ var Parser = class {
|
|
|
1856
1860
|
const position = this.clonePosition();
|
|
1857
1861
|
this.bump();
|
|
1858
1862
|
elements.push({
|
|
1859
|
-
type:
|
|
1863
|
+
type: 7,
|
|
1860
1864
|
location: createLocation(position, this.clonePosition())
|
|
1861
1865
|
});
|
|
1862
1866
|
} else if (char === 60 && !this.ignoreTag && this.peek() === 47) if (expectingCloseTag) break;
|
|
1863
|
-
else return this.error(
|
|
1867
|
+
else return this.error(26, createLocation(this.clonePosition(), this.clonePosition()));
|
|
1864
1868
|
else if (char === 60 && !this.ignoreTag && _isAlpha(this.peek() || 0)) {
|
|
1865
1869
|
const result = this.parseTag(nestingLevel, parentArgType);
|
|
1866
1870
|
if (result.err) return result;
|
|
@@ -1901,7 +1905,7 @@ var Parser = class {
|
|
|
1901
1905
|
this.bumpSpace();
|
|
1902
1906
|
if (this.bumpIf("/>")) return {
|
|
1903
1907
|
val: {
|
|
1904
|
-
type:
|
|
1908
|
+
type: 0,
|
|
1905
1909
|
value: `<${tagName}/>`,
|
|
1906
1910
|
location: createLocation(startPosition, this.clonePosition())
|
|
1907
1911
|
},
|
|
@@ -1913,22 +1917,22 @@ var Parser = class {
|
|
|
1913
1917
|
const children = childrenResult.val;
|
|
1914
1918
|
const endTagStartPosition = this.clonePosition();
|
|
1915
1919
|
if (this.bumpIf("</")) {
|
|
1916
|
-
if (this.isEOF() || !_isAlpha(this.char())) return this.error(
|
|
1920
|
+
if (this.isEOF() || !_isAlpha(this.char())) return this.error(23, createLocation(endTagStartPosition, this.clonePosition()));
|
|
1917
1921
|
const closingTagNameStartPosition = this.clonePosition();
|
|
1918
|
-
if (tagName !== this.parseTagName()) return this.error(
|
|
1922
|
+
if (tagName !== this.parseTagName()) return this.error(26, createLocation(closingTagNameStartPosition, this.clonePosition()));
|
|
1919
1923
|
this.bumpSpace();
|
|
1920
|
-
if (!this.bumpIf(">")) return this.error(
|
|
1924
|
+
if (!this.bumpIf(">")) return this.error(23, createLocation(endTagStartPosition, this.clonePosition()));
|
|
1921
1925
|
return {
|
|
1922
1926
|
val: {
|
|
1923
|
-
type:
|
|
1927
|
+
type: 8,
|
|
1924
1928
|
value: tagName,
|
|
1925
1929
|
children,
|
|
1926
1930
|
location: createLocation(startPosition, this.clonePosition())
|
|
1927
1931
|
},
|
|
1928
1932
|
err: null
|
|
1929
1933
|
};
|
|
1930
|
-
} else return this.error(
|
|
1931
|
-
} else return this.error(
|
|
1934
|
+
} else return this.error(27, createLocation(startPosition, this.clonePosition()));
|
|
1935
|
+
} else return this.error(23, createLocation(startPosition, this.clonePosition()));
|
|
1932
1936
|
}
|
|
1933
1937
|
/**
|
|
1934
1938
|
* This method assumes that the caller has peeked ahead for the first tag character.
|
|
@@ -1963,7 +1967,7 @@ var Parser = class {
|
|
|
1963
1967
|
const location = createLocation(start, this.clonePosition());
|
|
1964
1968
|
return {
|
|
1965
1969
|
val: {
|
|
1966
|
-
type:
|
|
1970
|
+
type: 0,
|
|
1967
1971
|
value,
|
|
1968
1972
|
location
|
|
1969
1973
|
},
|
|
@@ -2028,21 +2032,21 @@ var Parser = class {
|
|
|
2028
2032
|
const openingBracePosition = this.clonePosition();
|
|
2029
2033
|
this.bump();
|
|
2030
2034
|
this.bumpSpace();
|
|
2031
|
-
if (this.isEOF()) return this.error(
|
|
2035
|
+
if (this.isEOF()) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
|
|
2032
2036
|
if (this.char() === 125) {
|
|
2033
2037
|
this.bump();
|
|
2034
|
-
return this.error(
|
|
2038
|
+
return this.error(2, createLocation(openingBracePosition, this.clonePosition()));
|
|
2035
2039
|
}
|
|
2036
2040
|
let value = this.parseIdentifierIfPossible().value;
|
|
2037
|
-
if (!value) return this.error(
|
|
2041
|
+
if (!value) return this.error(3, createLocation(openingBracePosition, this.clonePosition()));
|
|
2038
2042
|
this.bumpSpace();
|
|
2039
|
-
if (this.isEOF()) return this.error(
|
|
2043
|
+
if (this.isEOF()) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
|
|
2040
2044
|
switch (this.char()) {
|
|
2041
2045
|
case 125:
|
|
2042
2046
|
this.bump();
|
|
2043
2047
|
return {
|
|
2044
2048
|
val: {
|
|
2045
|
-
type:
|
|
2049
|
+
type: 1,
|
|
2046
2050
|
value,
|
|
2047
2051
|
location: createLocation(openingBracePosition, this.clonePosition())
|
|
2048
2052
|
},
|
|
@@ -2051,9 +2055,9 @@ var Parser = class {
|
|
|
2051
2055
|
case 44:
|
|
2052
2056
|
this.bump();
|
|
2053
2057
|
this.bumpSpace();
|
|
2054
|
-
if (this.isEOF()) return this.error(
|
|
2058
|
+
if (this.isEOF()) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
|
|
2055
2059
|
return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition);
|
|
2056
|
-
default: return this.error(
|
|
2060
|
+
default: return this.error(3, createLocation(openingBracePosition, this.clonePosition()));
|
|
2057
2061
|
}
|
|
2058
2062
|
}
|
|
2059
2063
|
/**
|
|
@@ -2076,7 +2080,7 @@ var Parser = class {
|
|
|
2076
2080
|
let argType = this.parseIdentifierIfPossible().value;
|
|
2077
2081
|
let typeEndPosition = this.clonePosition();
|
|
2078
2082
|
switch (argType) {
|
|
2079
|
-
case "": return this.error(
|
|
2083
|
+
case "": return this.error(4, createLocation(typeStartPosition, typeEndPosition));
|
|
2080
2084
|
case "number":
|
|
2081
2085
|
case "date":
|
|
2082
2086
|
case "time": {
|
|
@@ -2088,7 +2092,7 @@ var Parser = class {
|
|
|
2088
2092
|
const result = this.parseSimpleArgStyleIfPossible();
|
|
2089
2093
|
if (result.err) return result;
|
|
2090
2094
|
const style = trimEnd(result.val);
|
|
2091
|
-
if (style.length === 0) return this.error(
|
|
2095
|
+
if (style.length === 0) return this.error(6, createLocation(this.clonePosition(), this.clonePosition()));
|
|
2092
2096
|
styleAndLocation = {
|
|
2093
2097
|
style,
|
|
2094
2098
|
styleLocation: createLocation(styleStartPosition, this.clonePosition())
|
|
@@ -2104,7 +2108,7 @@ var Parser = class {
|
|
|
2104
2108
|
if (result.err) return result;
|
|
2105
2109
|
return {
|
|
2106
2110
|
val: {
|
|
2107
|
-
type:
|
|
2111
|
+
type: 2,
|
|
2108
2112
|
value,
|
|
2109
2113
|
location,
|
|
2110
2114
|
style: result.val
|
|
@@ -2112,18 +2116,18 @@ var Parser = class {
|
|
|
2112
2116
|
err: null
|
|
2113
2117
|
};
|
|
2114
2118
|
} else {
|
|
2115
|
-
if (skeleton.length === 0) return this.error(
|
|
2119
|
+
if (skeleton.length === 0) return this.error(10, location);
|
|
2116
2120
|
let dateTimePattern = skeleton;
|
|
2117
2121
|
if (this.locale) dateTimePattern = getBestPattern(skeleton, this.locale);
|
|
2118
2122
|
const style = {
|
|
2119
|
-
type:
|
|
2123
|
+
type: 1,
|
|
2120
2124
|
pattern: dateTimePattern,
|
|
2121
2125
|
location: styleAndLocation.styleLocation,
|
|
2122
2126
|
parsedOptions: this.shouldParseSkeletons ? parseDateTimeSkeleton(dateTimePattern) : {}
|
|
2123
2127
|
};
|
|
2124
2128
|
return {
|
|
2125
2129
|
val: {
|
|
2126
|
-
type: argType === "date" ?
|
|
2130
|
+
type: argType === "date" ? 3 : 4,
|
|
2127
2131
|
value,
|
|
2128
2132
|
location,
|
|
2129
2133
|
style
|
|
@@ -2134,7 +2138,7 @@ var Parser = class {
|
|
|
2134
2138
|
}
|
|
2135
2139
|
return {
|
|
2136
2140
|
val: {
|
|
2137
|
-
type: argType === "number" ?
|
|
2141
|
+
type: argType === "number" ? 2 : argType === "date" ? 3 : 4,
|
|
2138
2142
|
value,
|
|
2139
2143
|
location,
|
|
2140
2144
|
style: styleAndLocation?.style ?? null
|
|
@@ -2147,14 +2151,14 @@ var Parser = class {
|
|
|
2147
2151
|
case "select": {
|
|
2148
2152
|
const typeEndPosition = this.clonePosition();
|
|
2149
2153
|
this.bumpSpace();
|
|
2150
|
-
if (!this.bumpIf(",")) return this.error(
|
|
2154
|
+
if (!this.bumpIf(",")) return this.error(12, createLocation(typeEndPosition, { ...typeEndPosition }));
|
|
2151
2155
|
this.bumpSpace();
|
|
2152
2156
|
let identifierAndLocation = this.parseIdentifierIfPossible();
|
|
2153
2157
|
let pluralOffset = 0;
|
|
2154
2158
|
if (argType !== "select" && identifierAndLocation.value === "offset") {
|
|
2155
|
-
if (!this.bumpIf(":")) return this.error(
|
|
2159
|
+
if (!this.bumpIf(":")) return this.error(13, createLocation(this.clonePosition(), this.clonePosition()));
|
|
2156
2160
|
this.bumpSpace();
|
|
2157
|
-
const result = this.tryParseDecimalInteger(
|
|
2161
|
+
const result = this.tryParseDecimalInteger(13, 14);
|
|
2158
2162
|
if (result.err) return result;
|
|
2159
2163
|
this.bumpSpace();
|
|
2160
2164
|
identifierAndLocation = this.parseIdentifierIfPossible();
|
|
@@ -2167,7 +2171,7 @@ var Parser = class {
|
|
|
2167
2171
|
const location = createLocation(openingBracePosition, this.clonePosition());
|
|
2168
2172
|
if (argType === "select") return {
|
|
2169
2173
|
val: {
|
|
2170
|
-
type:
|
|
2174
|
+
type: 5,
|
|
2171
2175
|
value,
|
|
2172
2176
|
options: fromEntries(optionsResult.val),
|
|
2173
2177
|
location
|
|
@@ -2176,7 +2180,7 @@ var Parser = class {
|
|
|
2176
2180
|
};
|
|
2177
2181
|
else return {
|
|
2178
2182
|
val: {
|
|
2179
|
-
type:
|
|
2183
|
+
type: 6,
|
|
2180
2184
|
value,
|
|
2181
2185
|
options: fromEntries(optionsResult.val),
|
|
2182
2186
|
offset: pluralOffset,
|
|
@@ -2186,11 +2190,11 @@ var Parser = class {
|
|
|
2186
2190
|
err: null
|
|
2187
2191
|
};
|
|
2188
2192
|
}
|
|
2189
|
-
default: return this.error(
|
|
2193
|
+
default: return this.error(5, createLocation(typeStartPosition, typeEndPosition));
|
|
2190
2194
|
}
|
|
2191
2195
|
}
|
|
2192
2196
|
tryParseArgumentClose(openingBracePosition) {
|
|
2193
|
-
if (this.isEOF() || this.char() !== 125) return this.error(
|
|
2197
|
+
if (this.isEOF() || this.char() !== 125) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
|
|
2194
2198
|
this.bump();
|
|
2195
2199
|
return {
|
|
2196
2200
|
val: true,
|
|
@@ -2207,7 +2211,7 @@ var Parser = class {
|
|
|
2207
2211
|
case 39: {
|
|
2208
2212
|
this.bump();
|
|
2209
2213
|
let apostrophePosition = this.clonePosition();
|
|
2210
|
-
if (!this.bumpUntil("'")) return this.error(
|
|
2214
|
+
if (!this.bumpUntil("'")) return this.error(11, createLocation(apostrophePosition, this.clonePosition()));
|
|
2211
2215
|
this.bump();
|
|
2212
2216
|
break;
|
|
2213
2217
|
}
|
|
@@ -2236,11 +2240,11 @@ var Parser = class {
|
|
|
2236
2240
|
try {
|
|
2237
2241
|
tokens = parseNumberSkeletonFromString(skeleton);
|
|
2238
2242
|
} catch {
|
|
2239
|
-
return this.error(
|
|
2243
|
+
return this.error(7, location);
|
|
2240
2244
|
}
|
|
2241
2245
|
return {
|
|
2242
2246
|
val: {
|
|
2243
|
-
type:
|
|
2247
|
+
type: 0,
|
|
2244
2248
|
tokens,
|
|
2245
2249
|
location,
|
|
2246
2250
|
parsedOptions: this.shouldParseSkeletons ? parseNumberSkeleton(tokens) : {}
|
|
@@ -2267,17 +2271,17 @@ var Parser = class {
|
|
|
2267
2271
|
if (selector.length === 0) {
|
|
2268
2272
|
const startPosition = this.clonePosition();
|
|
2269
2273
|
if (parentArgType !== "select" && this.bumpIf("=")) {
|
|
2270
|
-
const result = this.tryParseDecimalInteger(
|
|
2274
|
+
const result = this.tryParseDecimalInteger(16, 19);
|
|
2271
2275
|
if (result.err) return result;
|
|
2272
2276
|
selectorLocation = createLocation(startPosition, this.clonePosition());
|
|
2273
2277
|
selector = this.message.slice(startPosition.offset, this.offset());
|
|
2274
2278
|
} else break;
|
|
2275
2279
|
}
|
|
2276
|
-
if (parsedSelectors.has(selector)) return this.error(parentArgType === "select" ?
|
|
2280
|
+
if (parsedSelectors.has(selector)) return this.error(parentArgType === "select" ? 21 : 20, selectorLocation);
|
|
2277
2281
|
if (selector === "other") hasOtherClause = true;
|
|
2278
2282
|
this.bumpSpace();
|
|
2279
2283
|
const openingBracePosition = this.clonePosition();
|
|
2280
|
-
if (!this.bumpIf("{")) return this.error(parentArgType === "select" ?
|
|
2284
|
+
if (!this.bumpIf("{")) return this.error(parentArgType === "select" ? 17 : 18, createLocation(this.clonePosition(), this.clonePosition()));
|
|
2281
2285
|
const fragmentResult = this.parseMessage(nestingLevel + 1, parentArgType, expectCloseTag);
|
|
2282
2286
|
if (fragmentResult.err) return fragmentResult;
|
|
2283
2287
|
const argCloseResult = this.tryParseArgumentClose(openingBracePosition);
|
|
@@ -2290,8 +2294,8 @@ var Parser = class {
|
|
|
2290
2294
|
this.bumpSpace();
|
|
2291
2295
|
({value: selector, location: selectorLocation} = this.parseIdentifierIfPossible());
|
|
2292
2296
|
}
|
|
2293
|
-
if (options.length === 0) return this.error(parentArgType === "select" ?
|
|
2294
|
-
if (this.requiresOtherClause && !hasOtherClause) return this.error(
|
|
2297
|
+
if (options.length === 0) return this.error(parentArgType === "select" ? 15 : 16, createLocation(this.clonePosition(), this.clonePosition()));
|
|
2298
|
+
if (this.requiresOtherClause && !hasOtherClause) return this.error(22, createLocation(this.clonePosition(), this.clonePosition()));
|
|
2295
2299
|
return {
|
|
2296
2300
|
val: options,
|
|
2297
2301
|
err: null
|
|
@@ -2495,17 +2499,17 @@ var FormatError = class extends Error {
|
|
|
2495
2499
|
};
|
|
2496
2500
|
var InvalidValueError = class extends FormatError {
|
|
2497
2501
|
constructor(variableId, value, options, originalMessage) {
|
|
2498
|
-
super(`Invalid values for "${variableId}": "${value}". Options are "${Object.keys(options).join("\", \"")}"`,
|
|
2502
|
+
super(`Invalid values for "${variableId}": "${value}". Options are "${Object.keys(options).join("\", \"")}"`, "INVALID_VALUE", originalMessage);
|
|
2499
2503
|
}
|
|
2500
2504
|
};
|
|
2501
2505
|
var InvalidValueTypeError = class extends FormatError {
|
|
2502
2506
|
constructor(value, type, originalMessage) {
|
|
2503
|
-
super(`Value for "${value}" must be of type ${type}`,
|
|
2507
|
+
super(`Value for "${value}" must be of type ${type}`, "INVALID_VALUE", originalMessage);
|
|
2504
2508
|
}
|
|
2505
2509
|
};
|
|
2506
2510
|
var MissingValueError = class extends FormatError {
|
|
2507
2511
|
constructor(variableId, originalMessage) {
|
|
2508
|
-
super(`The intl string context variable "${variableId}" was not provided to the string "${originalMessage}"`,
|
|
2512
|
+
super(`The intl string context variable "${variableId}" was not provided to the string "${originalMessage}"`, "MISSING_VALUE", originalMessage);
|
|
2509
2513
|
}
|
|
2510
2514
|
};
|
|
2511
2515
|
//#endregion
|
|
@@ -2519,7 +2523,7 @@ function mergeLiteral(parts) {
|
|
|
2519
2523
|
if (parts.length < 2) return parts;
|
|
2520
2524
|
return parts.reduce((all, part) => {
|
|
2521
2525
|
const lastPart = all[all.length - 1];
|
|
2522
|
-
if (!lastPart || lastPart.type !==
|
|
2526
|
+
if (!lastPart || lastPart.type !== 0 || part.type !== 0) all.push(part);
|
|
2523
2527
|
else lastPart.value += part.value;
|
|
2524
2528
|
return all;
|
|
2525
2529
|
}, []);
|
|
@@ -2529,21 +2533,21 @@ function isFormatXMLElementFn(el) {
|
|
|
2529
2533
|
}
|
|
2530
2534
|
function formatToParts(els, locales, formatters, formats, values, currentPluralValue, originalMessage) {
|
|
2531
2535
|
if (els.length === 1 && isLiteralElement(els[0])) return [{
|
|
2532
|
-
type:
|
|
2536
|
+
type: 0,
|
|
2533
2537
|
value: els[0].value
|
|
2534
2538
|
}];
|
|
2535
2539
|
const result = [];
|
|
2536
2540
|
for (const el of els) {
|
|
2537
2541
|
if (isLiteralElement(el)) {
|
|
2538
2542
|
result.push({
|
|
2539
|
-
type:
|
|
2543
|
+
type: 0,
|
|
2540
2544
|
value: el.value
|
|
2541
2545
|
});
|
|
2542
2546
|
continue;
|
|
2543
2547
|
}
|
|
2544
2548
|
if (isPoundElement(el)) {
|
|
2545
2549
|
if (typeof currentPluralValue === "number") result.push({
|
|
2546
|
-
type:
|
|
2550
|
+
type: 0,
|
|
2547
2551
|
value: formatters.getNumberFormat(locales).format(currentPluralValue)
|
|
2548
2552
|
});
|
|
2549
2553
|
continue;
|
|
@@ -2554,7 +2558,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2554
2558
|
if (isArgumentElement(el)) {
|
|
2555
2559
|
if (!value || typeof value === "string" || typeof value === "number" || typeof value === "bigint") value = typeof value === "string" || typeof value === "number" || typeof value === "bigint" ? String(value) : "";
|
|
2556
2560
|
result.push({
|
|
2557
|
-
type: typeof value === "string" ?
|
|
2561
|
+
type: typeof value === "string" ? 0 : 1,
|
|
2558
2562
|
value
|
|
2559
2563
|
});
|
|
2560
2564
|
continue;
|
|
@@ -2562,7 +2566,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2562
2566
|
if (isDateElement(el)) {
|
|
2563
2567
|
const style = typeof el.style === "string" ? formats.date[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : void 0;
|
|
2564
2568
|
result.push({
|
|
2565
|
-
type:
|
|
2569
|
+
type: 0,
|
|
2566
2570
|
value: formatters.getDateTimeFormat(locales, style).format(value)
|
|
2567
2571
|
});
|
|
2568
2572
|
continue;
|
|
@@ -2570,7 +2574,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2570
2574
|
if (isTimeElement(el)) {
|
|
2571
2575
|
const style = typeof el.style === "string" ? formats.time[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : formats.time.medium;
|
|
2572
2576
|
result.push({
|
|
2573
|
-
type:
|
|
2577
|
+
type: 0,
|
|
2574
2578
|
value: formatters.getDateTimeFormat(locales, style).format(value)
|
|
2575
2579
|
});
|
|
2576
2580
|
continue;
|
|
@@ -2585,7 +2589,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2585
2589
|
} else value = value * scale;
|
|
2586
2590
|
}
|
|
2587
2591
|
result.push({
|
|
2588
|
-
type:
|
|
2592
|
+
type: 0,
|
|
2589
2593
|
value: formatters.getNumberFormat(locales, style).format(value)
|
|
2590
2594
|
});
|
|
2591
2595
|
continue;
|
|
@@ -2598,7 +2602,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2598
2602
|
if (!Array.isArray(chunks)) chunks = [chunks];
|
|
2599
2603
|
result.push(...chunks.map((c) => {
|
|
2600
2604
|
return {
|
|
2601
|
-
type: typeof c === "string" ?
|
|
2605
|
+
type: typeof c === "string" ? 0 : 1,
|
|
2602
2606
|
value: c
|
|
2603
2607
|
};
|
|
2604
2608
|
}));
|
|
@@ -2616,7 +2620,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2616
2620
|
if (!opt) {
|
|
2617
2621
|
if (!Intl.PluralRules) throw new FormatError(`Intl.PluralRules is not available in this environment.
|
|
2618
2622
|
Try polyfilling it using "@formatjs/intl-pluralrules"
|
|
2619
|
-
`,
|
|
2623
|
+
`, "MISSING_INTL_API", originalMessage);
|
|
2620
2624
|
const numericValue = typeof value === "bigint" ? Number(value) : value;
|
|
2621
2625
|
const rule = formatters.getPluralRules(locales, { type: el.pluralType }).select(numericValue - (el.offset || 0));
|
|
2622
2626
|
opt = (Object.prototype.hasOwnProperty.call(el.options, rule) ? el.options[rule] : void 0) || el.options.other;
|
|
@@ -2695,7 +2699,7 @@ var IntlMessageFormat = class IntlMessageFormat {
|
|
|
2695
2699
|
const parts = this.formatToParts(values);
|
|
2696
2700
|
if (parts.length === 1) return parts[0].value;
|
|
2697
2701
|
const result = parts.reduce((all, part) => {
|
|
2698
|
-
if (!all.length || part.type !==
|
|
2702
|
+
if (!all.length || part.type !== 0 || typeof all[all.length - 1] !== "string") all.push(part.value);
|
|
2699
2703
|
else all[all.length - 1] += part.value;
|
|
2700
2704
|
return all;
|
|
2701
2705
|
}, []);
|
package/package.json
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-messageformat",
|
|
3
|
+
"version": "11.2.8",
|
|
3
4
|
"description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
|
|
4
|
-
"version": "11.2.6",
|
|
5
|
-
"license": "BSD-3-Clause",
|
|
6
|
-
"author": "Eric Ferraiuolo <eferraiuolo@gmail.com>",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"sideEffects": false,
|
|
9
|
-
"types": "index.d.ts",
|
|
10
|
-
"exports": {
|
|
11
|
-
".": "./index.js"
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"@formatjs/fast-memoize": "3.1.5",
|
|
15
|
-
"@formatjs/icu-messageformat-parser": "3.5.9"
|
|
16
|
-
},
|
|
17
|
-
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
18
|
-
"contributors": [
|
|
19
|
-
"Anthony Pipkin <a.pipkin@yahoo.com>",
|
|
20
|
-
"Caridy Patino <caridy@gmail.com>",
|
|
21
|
-
"Drew Folta <drew@folta.net>",
|
|
22
|
-
"Long Ho <holevietlong@gmail.com>"
|
|
23
|
-
],
|
|
24
|
-
"gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c",
|
|
25
|
-
"homepage": "https://github.com/formatjs/formatjs",
|
|
26
5
|
"keywords": [
|
|
27
6
|
"globalization",
|
|
28
7
|
"i18n",
|
|
@@ -34,5 +13,25 @@
|
|
|
34
13
|
"parser",
|
|
35
14
|
"plural"
|
|
36
15
|
],
|
|
37
|
-
"
|
|
16
|
+
"homepage": "https://github.com/formatjs/formatjs",
|
|
17
|
+
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
18
|
+
"license": "BSD-3-Clause",
|
|
19
|
+
"author": "Eric Ferraiuolo <eferraiuolo@gmail.com>",
|
|
20
|
+
"contributors": [
|
|
21
|
+
"Anthony Pipkin <a.pipkin@yahoo.com>",
|
|
22
|
+
"Caridy Patino <caridy@gmail.com>",
|
|
23
|
+
"Drew Folta <drew@folta.net>",
|
|
24
|
+
"Long Ho <holevietlong@gmail.com>"
|
|
25
|
+
],
|
|
26
|
+
"repository": "git@github.com:formatjs/formatjs.git",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"types": "index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./index.js"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@formatjs/fast-memoize": "3.1.6",
|
|
35
|
+
"@formatjs/icu-messageformat-parser": "3.5.11"
|
|
36
|
+
}
|
|
38
37
|
}
|