intl-messageformat 11.2.5 → 11.2.7

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 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("\", \"")}"`, ErrorCode.INVALID_VALUE, originalMessage);
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}`, ErrorCode.INVALID_VALUE, originalMessage);
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}"`, ErrorCode.MISSING_VALUE, 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 !== PART_TYPE.literal || part.type !== PART_TYPE.literal) all.push(part);
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: PART_TYPE.literal,
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: PART_TYPE.literal,
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: PART_TYPE.literal,
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" ? PART_TYPE.literal : PART_TYPE.object,
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: PART_TYPE.literal,
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: PART_TYPE.literal,
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: PART_TYPE.literal,
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" ? PART_TYPE.literal : PART_TYPE.object,
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
- `, ErrorCode.MISSING_INTL_API, originalMessage);
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 !== PART_TYPE.literal || typeof all[all.length - 1] !== "string") all.push(part.value);
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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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'\n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K,OAAO,OAAO,YAAY,WAAW,UAAU,QAAQ,EAAE;EAC3E;;;iBAC2C;;;iBAIjB;GACxB,QAAQ;IACN,SAAS,EACP,uBAAuB,EACzB;IACA,UAAU,EACR,OAAO,WACT;IAEA,SAAS,EACP,OAAO,UACT;GACF;GAEA,MAAM;IACJ,OAAO;KACL,OAAO;KACP,KAAK;KACL,MAAM;IACR;IAEA,QAAQ;KACN,OAAO;KACP,KAAK;KACL,MAAM;IACR;IAEA,MAAM;KACJ,OAAO;KACP,KAAK;KACL,MAAM;IACR;IAEA,MAAM;KACJ,SAAS;KACT,OAAO;KACP,KAAK;KACL,MAAM;IACR;GACF;GAEA,MAAM;IACJ,OAAO;KACL,MAAM;KACN,QAAQ;IACV;IAEA,QAAQ;KACN,MAAM;KACN,QAAQ;KACR,QAAQ;IACV;IAEA,MAAM;KACJ,MAAM;KACN,QAAQ;KACR,QAAQ;KACR,cAAc;IAChB;IAEA,MAAM;KACJ,MAAM;KACN,QAAQ;KACR,QAAQ;KACR,cAAc;IAChB;GACF;EACF;;AACF;;;AC/RA,IAAA,6BAAe"}
@@ -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 === TYPE.literal;
508
+ return el.type === 0;
554
509
  }
555
510
  function isArgumentElement(el) {
556
- return el.type === TYPE.argument;
511
+ return el.type === 1;
557
512
  }
558
513
  function isNumberElement(el) {
559
- return el.type === TYPE.number;
514
+ return el.type === 2;
560
515
  }
561
516
  function isDateElement(el) {
562
- return el.type === TYPE.date;
517
+ return el.type === 3;
563
518
  }
564
519
  function isTimeElement(el) {
565
- return el.type === TYPE.time;
520
+ return el.type === 4;
566
521
  }
567
522
  function isSelectElement(el) {
568
- return el.type === TYPE.select;
523
+ return el.type === 5;
569
524
  }
570
525
  function isPluralElement(el) {
571
- return el.type === TYPE.plural;
526
+ return el.type === 6;
572
527
  }
573
528
  function isPoundElement(el) {
574
- return el.type === TYPE.pound;
529
+ return el.type === 7;
575
530
  }
576
531
  function isTagElement(el) {
577
- return el.type === TYPE.tag;
532
+ return el.type === 8;
578
533
  }
579
534
  function isNumberSkeleton(el) {
580
- return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.number);
535
+ return !!(el && typeof el === "object" && el.type === 0);
581
536
  }
582
537
  function isDateTimeSkeleton(el) {
583
- return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.dateTime);
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 = {
@@ -1856,11 +1811,11 @@ var Parser = class {
1856
1811
  const position = this.clonePosition();
1857
1812
  this.bump();
1858
1813
  elements.push({
1859
- type: TYPE.pound,
1814
+ type: 7,
1860
1815
  location: createLocation(position, this.clonePosition())
1861
1816
  });
1862
1817
  } else if (char === 60 && !this.ignoreTag && this.peek() === 47) if (expectingCloseTag) break;
1863
- else return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition()));
1818
+ else return this.error(26, createLocation(this.clonePosition(), this.clonePosition()));
1864
1819
  else if (char === 60 && !this.ignoreTag && _isAlpha(this.peek() || 0)) {
1865
1820
  const result = this.parseTag(nestingLevel, parentArgType);
1866
1821
  if (result.err) return result;
@@ -1901,7 +1856,7 @@ var Parser = class {
1901
1856
  this.bumpSpace();
1902
1857
  if (this.bumpIf("/>")) return {
1903
1858
  val: {
1904
- type: TYPE.literal,
1859
+ type: 0,
1905
1860
  value: `<${tagName}/>`,
1906
1861
  location: createLocation(startPosition, this.clonePosition())
1907
1862
  },
@@ -1913,22 +1868,22 @@ var Parser = class {
1913
1868
  const children = childrenResult.val;
1914
1869
  const endTagStartPosition = this.clonePosition();
1915
1870
  if (this.bumpIf("</")) {
1916
- if (this.isEOF() || !_isAlpha(this.char())) return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
1871
+ if (this.isEOF() || !_isAlpha(this.char())) return this.error(23, createLocation(endTagStartPosition, this.clonePosition()));
1917
1872
  const closingTagNameStartPosition = this.clonePosition();
1918
- if (tagName !== this.parseTagName()) return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition()));
1873
+ if (tagName !== this.parseTagName()) return this.error(26, createLocation(closingTagNameStartPosition, this.clonePosition()));
1919
1874
  this.bumpSpace();
1920
- if (!this.bumpIf(">")) return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
1875
+ if (!this.bumpIf(">")) return this.error(23, createLocation(endTagStartPosition, this.clonePosition()));
1921
1876
  return {
1922
1877
  val: {
1923
- type: TYPE.tag,
1878
+ type: 8,
1924
1879
  value: tagName,
1925
1880
  children,
1926
1881
  location: createLocation(startPosition, this.clonePosition())
1927
1882
  },
1928
1883
  err: null
1929
1884
  };
1930
- } else return this.error(ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition()));
1931
- } else return this.error(ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition()));
1885
+ } else return this.error(27, createLocation(startPosition, this.clonePosition()));
1886
+ } else return this.error(23, createLocation(startPosition, this.clonePosition()));
1932
1887
  }
1933
1888
  /**
1934
1889
  * This method assumes that the caller has peeked ahead for the first tag character.
@@ -1963,7 +1918,7 @@ var Parser = class {
1963
1918
  const location = createLocation(start, this.clonePosition());
1964
1919
  return {
1965
1920
  val: {
1966
- type: TYPE.literal,
1921
+ type: 0,
1967
1922
  value,
1968
1923
  location
1969
1924
  },
@@ -2028,21 +1983,21 @@ var Parser = class {
2028
1983
  const openingBracePosition = this.clonePosition();
2029
1984
  this.bump();
2030
1985
  this.bumpSpace();
2031
- if (this.isEOF()) return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
1986
+ if (this.isEOF()) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
2032
1987
  if (this.char() === 125) {
2033
1988
  this.bump();
2034
- return this.error(ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
1989
+ return this.error(2, createLocation(openingBracePosition, this.clonePosition()));
2035
1990
  }
2036
1991
  let value = this.parseIdentifierIfPossible().value;
2037
- if (!value) return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
1992
+ if (!value) return this.error(3, createLocation(openingBracePosition, this.clonePosition()));
2038
1993
  this.bumpSpace();
2039
- if (this.isEOF()) return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
1994
+ if (this.isEOF()) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
2040
1995
  switch (this.char()) {
2041
1996
  case 125:
2042
1997
  this.bump();
2043
1998
  return {
2044
1999
  val: {
2045
- type: TYPE.argument,
2000
+ type: 1,
2046
2001
  value,
2047
2002
  location: createLocation(openingBracePosition, this.clonePosition())
2048
2003
  },
@@ -2051,9 +2006,9 @@ var Parser = class {
2051
2006
  case 44:
2052
2007
  this.bump();
2053
2008
  this.bumpSpace();
2054
- if (this.isEOF()) return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
2009
+ if (this.isEOF()) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
2055
2010
  return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition);
2056
- default: return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
2011
+ default: return this.error(3, createLocation(openingBracePosition, this.clonePosition()));
2057
2012
  }
2058
2013
  }
2059
2014
  /**
@@ -2076,7 +2031,7 @@ var Parser = class {
2076
2031
  let argType = this.parseIdentifierIfPossible().value;
2077
2032
  let typeEndPosition = this.clonePosition();
2078
2033
  switch (argType) {
2079
- case "": return this.error(ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
2034
+ case "": return this.error(4, createLocation(typeStartPosition, typeEndPosition));
2080
2035
  case "number":
2081
2036
  case "date":
2082
2037
  case "time": {
@@ -2088,7 +2043,7 @@ var Parser = class {
2088
2043
  const result = this.parseSimpleArgStyleIfPossible();
2089
2044
  if (result.err) return result;
2090
2045
  const style = trimEnd(result.val);
2091
- if (style.length === 0) return this.error(ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition()));
2046
+ if (style.length === 0) return this.error(6, createLocation(this.clonePosition(), this.clonePosition()));
2092
2047
  styleAndLocation = {
2093
2048
  style,
2094
2049
  styleLocation: createLocation(styleStartPosition, this.clonePosition())
@@ -2104,7 +2059,7 @@ var Parser = class {
2104
2059
  if (result.err) return result;
2105
2060
  return {
2106
2061
  val: {
2107
- type: TYPE.number,
2062
+ type: 2,
2108
2063
  value,
2109
2064
  location,
2110
2065
  style: result.val
@@ -2112,18 +2067,18 @@ var Parser = class {
2112
2067
  err: null
2113
2068
  };
2114
2069
  } else {
2115
- if (skeleton.length === 0) return this.error(ErrorKind.EXPECT_DATE_TIME_SKELETON, location);
2070
+ if (skeleton.length === 0) return this.error(10, location);
2116
2071
  let dateTimePattern = skeleton;
2117
2072
  if (this.locale) dateTimePattern = getBestPattern(skeleton, this.locale);
2118
2073
  const style = {
2119
- type: SKELETON_TYPE.dateTime,
2074
+ type: 1,
2120
2075
  pattern: dateTimePattern,
2121
2076
  location: styleAndLocation.styleLocation,
2122
2077
  parsedOptions: this.shouldParseSkeletons ? parseDateTimeSkeleton(dateTimePattern) : {}
2123
2078
  };
2124
2079
  return {
2125
2080
  val: {
2126
- type: argType === "date" ? TYPE.date : TYPE.time,
2081
+ type: argType === "date" ? 3 : 4,
2127
2082
  value,
2128
2083
  location,
2129
2084
  style
@@ -2134,7 +2089,7 @@ var Parser = class {
2134
2089
  }
2135
2090
  return {
2136
2091
  val: {
2137
- type: argType === "number" ? TYPE.number : argType === "date" ? TYPE.date : TYPE.time,
2092
+ type: argType === "number" ? 2 : argType === "date" ? 3 : 4,
2138
2093
  value,
2139
2094
  location,
2140
2095
  style: styleAndLocation?.style ?? null
@@ -2147,14 +2102,14 @@ var Parser = class {
2147
2102
  case "select": {
2148
2103
  const typeEndPosition = this.clonePosition();
2149
2104
  this.bumpSpace();
2150
- if (!this.bumpIf(",")) return this.error(ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition, { ...typeEndPosition }));
2105
+ if (!this.bumpIf(",")) return this.error(12, createLocation(typeEndPosition, { ...typeEndPosition }));
2151
2106
  this.bumpSpace();
2152
2107
  let identifierAndLocation = this.parseIdentifierIfPossible();
2153
2108
  let pluralOffset = 0;
2154
2109
  if (argType !== "select" && identifierAndLocation.value === "offset") {
2155
- if (!this.bumpIf(":")) return this.error(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition()));
2110
+ if (!this.bumpIf(":")) return this.error(13, createLocation(this.clonePosition(), this.clonePosition()));
2156
2111
  this.bumpSpace();
2157
- const result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE);
2112
+ const result = this.tryParseDecimalInteger(13, 14);
2158
2113
  if (result.err) return result;
2159
2114
  this.bumpSpace();
2160
2115
  identifierAndLocation = this.parseIdentifierIfPossible();
@@ -2167,7 +2122,7 @@ var Parser = class {
2167
2122
  const location = createLocation(openingBracePosition, this.clonePosition());
2168
2123
  if (argType === "select") return {
2169
2124
  val: {
2170
- type: TYPE.select,
2125
+ type: 5,
2171
2126
  value,
2172
2127
  options: fromEntries(optionsResult.val),
2173
2128
  location
@@ -2176,7 +2131,7 @@ var Parser = class {
2176
2131
  };
2177
2132
  else return {
2178
2133
  val: {
2179
- type: TYPE.plural,
2134
+ type: 6,
2180
2135
  value,
2181
2136
  options: fromEntries(optionsResult.val),
2182
2137
  offset: pluralOffset,
@@ -2186,11 +2141,11 @@ var Parser = class {
2186
2141
  err: null
2187
2142
  };
2188
2143
  }
2189
- default: return this.error(ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
2144
+ default: return this.error(5, createLocation(typeStartPosition, typeEndPosition));
2190
2145
  }
2191
2146
  }
2192
2147
  tryParseArgumentClose(openingBracePosition) {
2193
- if (this.isEOF() || this.char() !== 125) return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
2148
+ if (this.isEOF() || this.char() !== 125) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
2194
2149
  this.bump();
2195
2150
  return {
2196
2151
  val: true,
@@ -2207,7 +2162,7 @@ var Parser = class {
2207
2162
  case 39: {
2208
2163
  this.bump();
2209
2164
  let apostrophePosition = this.clonePosition();
2210
- if (!this.bumpUntil("'")) return this.error(ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition()));
2165
+ if (!this.bumpUntil("'")) return this.error(11, createLocation(apostrophePosition, this.clonePosition()));
2211
2166
  this.bump();
2212
2167
  break;
2213
2168
  }
@@ -2236,11 +2191,11 @@ var Parser = class {
2236
2191
  try {
2237
2192
  tokens = parseNumberSkeletonFromString(skeleton);
2238
2193
  } catch {
2239
- return this.error(ErrorKind.INVALID_NUMBER_SKELETON, location);
2194
+ return this.error(7, location);
2240
2195
  }
2241
2196
  return {
2242
2197
  val: {
2243
- type: SKELETON_TYPE.number,
2198
+ type: 0,
2244
2199
  tokens,
2245
2200
  location,
2246
2201
  parsedOptions: this.shouldParseSkeletons ? parseNumberSkeleton(tokens) : {}
@@ -2267,17 +2222,17 @@ var Parser = class {
2267
2222
  if (selector.length === 0) {
2268
2223
  const startPosition = this.clonePosition();
2269
2224
  if (parentArgType !== "select" && this.bumpIf("=")) {
2270
- const result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR);
2225
+ const result = this.tryParseDecimalInteger(16, 19);
2271
2226
  if (result.err) return result;
2272
2227
  selectorLocation = createLocation(startPosition, this.clonePosition());
2273
2228
  selector = this.message.slice(startPosition.offset, this.offset());
2274
2229
  } else break;
2275
2230
  }
2276
- if (parsedSelectors.has(selector)) return this.error(parentArgType === "select" ? ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR : ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation);
2231
+ if (parsedSelectors.has(selector)) return this.error(parentArgType === "select" ? 21 : 20, selectorLocation);
2277
2232
  if (selector === "other") hasOtherClause = true;
2278
2233
  this.bumpSpace();
2279
2234
  const openingBracePosition = this.clonePosition();
2280
- if (!this.bumpIf("{")) return this.error(parentArgType === "select" ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT : ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition()));
2235
+ if (!this.bumpIf("{")) return this.error(parentArgType === "select" ? 17 : 18, createLocation(this.clonePosition(), this.clonePosition()));
2281
2236
  const fragmentResult = this.parseMessage(nestingLevel + 1, parentArgType, expectCloseTag);
2282
2237
  if (fragmentResult.err) return fragmentResult;
2283
2238
  const argCloseResult = this.tryParseArgumentClose(openingBracePosition);
@@ -2290,8 +2245,8 @@ var Parser = class {
2290
2245
  this.bumpSpace();
2291
2246
  ({value: selector, location: selectorLocation} = this.parseIdentifierIfPossible());
2292
2247
  }
2293
- if (options.length === 0) return this.error(parentArgType === "select" ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR : ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition()));
2294
- if (this.requiresOtherClause && !hasOtherClause) return this.error(ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition()));
2248
+ if (options.length === 0) return this.error(parentArgType === "select" ? 15 : 16, createLocation(this.clonePosition(), this.clonePosition()));
2249
+ if (this.requiresOtherClause && !hasOtherClause) return this.error(22, createLocation(this.clonePosition(), this.clonePosition()));
2295
2250
  return {
2296
2251
  val: options,
2297
2252
  err: null
@@ -2495,17 +2450,17 @@ var FormatError = class extends Error {
2495
2450
  };
2496
2451
  var InvalidValueError = class extends FormatError {
2497
2452
  constructor(variableId, value, options, originalMessage) {
2498
- super(`Invalid values for "${variableId}": "${value}". Options are "${Object.keys(options).join("\", \"")}"`, ErrorCode.INVALID_VALUE, originalMessage);
2453
+ super(`Invalid values for "${variableId}": "${value}". Options are "${Object.keys(options).join("\", \"")}"`, "INVALID_VALUE", originalMessage);
2499
2454
  }
2500
2455
  };
2501
2456
  var InvalidValueTypeError = class extends FormatError {
2502
2457
  constructor(value, type, originalMessage) {
2503
- super(`Value for "${value}" must be of type ${type}`, ErrorCode.INVALID_VALUE, originalMessage);
2458
+ super(`Value for "${value}" must be of type ${type}`, "INVALID_VALUE", originalMessage);
2504
2459
  }
2505
2460
  };
2506
2461
  var MissingValueError = class extends FormatError {
2507
2462
  constructor(variableId, originalMessage) {
2508
- super(`The intl string context variable "${variableId}" was not provided to the string "${originalMessage}"`, ErrorCode.MISSING_VALUE, originalMessage);
2463
+ super(`The intl string context variable "${variableId}" was not provided to the string "${originalMessage}"`, "MISSING_VALUE", originalMessage);
2509
2464
  }
2510
2465
  };
2511
2466
  //#endregion
@@ -2519,7 +2474,7 @@ function mergeLiteral(parts) {
2519
2474
  if (parts.length < 2) return parts;
2520
2475
  return parts.reduce((all, part) => {
2521
2476
  const lastPart = all[all.length - 1];
2522
- if (!lastPart || lastPart.type !== PART_TYPE.literal || part.type !== PART_TYPE.literal) all.push(part);
2477
+ if (!lastPart || lastPart.type !== 0 || part.type !== 0) all.push(part);
2523
2478
  else lastPart.value += part.value;
2524
2479
  return all;
2525
2480
  }, []);
@@ -2529,21 +2484,21 @@ function isFormatXMLElementFn(el) {
2529
2484
  }
2530
2485
  function formatToParts(els, locales, formatters, formats, values, currentPluralValue, originalMessage) {
2531
2486
  if (els.length === 1 && isLiteralElement(els[0])) return [{
2532
- type: PART_TYPE.literal,
2487
+ type: 0,
2533
2488
  value: els[0].value
2534
2489
  }];
2535
2490
  const result = [];
2536
2491
  for (const el of els) {
2537
2492
  if (isLiteralElement(el)) {
2538
2493
  result.push({
2539
- type: PART_TYPE.literal,
2494
+ type: 0,
2540
2495
  value: el.value
2541
2496
  });
2542
2497
  continue;
2543
2498
  }
2544
2499
  if (isPoundElement(el)) {
2545
2500
  if (typeof currentPluralValue === "number") result.push({
2546
- type: PART_TYPE.literal,
2501
+ type: 0,
2547
2502
  value: formatters.getNumberFormat(locales).format(currentPluralValue)
2548
2503
  });
2549
2504
  continue;
@@ -2554,7 +2509,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2554
2509
  if (isArgumentElement(el)) {
2555
2510
  if (!value || typeof value === "string" || typeof value === "number" || typeof value === "bigint") value = typeof value === "string" || typeof value === "number" || typeof value === "bigint" ? String(value) : "";
2556
2511
  result.push({
2557
- type: typeof value === "string" ? PART_TYPE.literal : PART_TYPE.object,
2512
+ type: typeof value === "string" ? 0 : 1,
2558
2513
  value
2559
2514
  });
2560
2515
  continue;
@@ -2562,7 +2517,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2562
2517
  if (isDateElement(el)) {
2563
2518
  const style = typeof el.style === "string" ? formats.date[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : void 0;
2564
2519
  result.push({
2565
- type: PART_TYPE.literal,
2520
+ type: 0,
2566
2521
  value: formatters.getDateTimeFormat(locales, style).format(value)
2567
2522
  });
2568
2523
  continue;
@@ -2570,7 +2525,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2570
2525
  if (isTimeElement(el)) {
2571
2526
  const style = typeof el.style === "string" ? formats.time[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : formats.time.medium;
2572
2527
  result.push({
2573
- type: PART_TYPE.literal,
2528
+ type: 0,
2574
2529
  value: formatters.getDateTimeFormat(locales, style).format(value)
2575
2530
  });
2576
2531
  continue;
@@ -2585,7 +2540,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2585
2540
  } else value = value * scale;
2586
2541
  }
2587
2542
  result.push({
2588
- type: PART_TYPE.literal,
2543
+ type: 0,
2589
2544
  value: formatters.getNumberFormat(locales, style).format(value)
2590
2545
  });
2591
2546
  continue;
@@ -2598,7 +2553,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2598
2553
  if (!Array.isArray(chunks)) chunks = [chunks];
2599
2554
  result.push(...chunks.map((c) => {
2600
2555
  return {
2601
- type: typeof c === "string" ? PART_TYPE.literal : PART_TYPE.object,
2556
+ type: typeof c === "string" ? 0 : 1,
2602
2557
  value: c
2603
2558
  };
2604
2559
  }));
@@ -2616,7 +2571,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2616
2571
  if (!opt) {
2617
2572
  if (!Intl.PluralRules) throw new FormatError(`Intl.PluralRules is not available in this environment.
2618
2573
  Try polyfilling it using "@formatjs/intl-pluralrules"
2619
- `, ErrorCode.MISSING_INTL_API, originalMessage);
2574
+ `, "MISSING_INTL_API", originalMessage);
2620
2575
  const numericValue = typeof value === "bigint" ? Number(value) : value;
2621
2576
  const rule = formatters.getPluralRules(locales, { type: el.pluralType }).select(numericValue - (el.offset || 0));
2622
2577
  opt = (Object.prototype.hasOwnProperty.call(el.options, rule) ? el.options[rule] : void 0) || el.options.other;
@@ -2695,7 +2650,7 @@ var IntlMessageFormat = class IntlMessageFormat {
2695
2650
  const parts = this.formatToParts(values);
2696
2651
  if (parts.length === 1) return parts[0].value;
2697
2652
  const result = parts.reduce((all, part) => {
2698
- if (!all.length || part.type !== PART_TYPE.literal || typeof all[all.length - 1] !== "string") all.push(part.value);
2653
+ if (!all.length || part.type !== 0 || typeof all[all.length - 1] !== "string") all.push(part.value);
2699
2654
  else all[all.length - 1] += part.value;
2700
2655
  return all;
2701
2656
  }, []);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "intl-messageformat",
3
3
  "description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
4
- "version": "11.2.5",
4
+ "version": "11.2.7",
5
5
  "license": "BSD-3-Clause",
6
6
  "author": "Eric Ferraiuolo <eferraiuolo@gmail.com>",
7
7
  "type": "module",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@formatjs/fast-memoize": "3.1.5",
15
- "@formatjs/icu-messageformat-parser": "3.5.8"
15
+ "@formatjs/icu-messageformat-parser": "3.5.10"
16
16
  },
17
17
  "bugs": "https://github.com/formatjs/formatjs/issues",
18
18
  "contributors": [