intl-messageformat 11.2.15 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +31 -4
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/intl-messageformat.iife.js +3 -3
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -84,11 +84,38 @@ export declare function isFormatXMLElementFn<T>(el: PrimitiveType | T | FormatXM
|
|
|
84
84
|
export declare function formatToParts<T>(els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, currentPluralValue?: number, originalMessage?: string): MessageFormatPart<T>[];
|
|
85
85
|
export type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (parts: Array<string | T>) => R;
|
|
86
86
|
//#endregion
|
|
87
|
+
//#region packages/intl-messageformat/message-types.d.ts
|
|
88
|
+
declare const messageValues: unique symbol;
|
|
89
|
+
declare const messageTag: unique symbol;
|
|
90
|
+
/** An unformatted ICU argument, before framework-specific rich values are added. */
|
|
91
|
+
type MessageValue = PrimitiveType;
|
|
92
|
+
/** A tag placeholder whose callback type is supplied by the formatter. */
|
|
93
|
+
interface MessageTag {
|
|
94
|
+
readonly [messageTag]: true;
|
|
95
|
+
}
|
|
96
|
+
type MessageValues = Record<string, MessageValue | MessageTag>;
|
|
97
|
+
/** Type-only argument metadata shared by formatter integrations. */
|
|
98
|
+
interface MessageContract<V extends MessageValues> {
|
|
99
|
+
readonly [messageValues]: V;
|
|
100
|
+
}
|
|
101
|
+
type MessageValuesOf<D extends MessageContract<MessageValues>> = D[typeof messageValues];
|
|
102
|
+
interface UntypedMessageContract {
|
|
103
|
+
readonly [messageValues]?: never;
|
|
104
|
+
}
|
|
105
|
+
type ResolveMessageValues<V extends MessageValues, T, TChunk> = { [K in keyof V]: [V[K]] extends [undefined] ? V[K] : Exclude<V[K], undefined> extends MessageTag ? FormatXMLElementFn<string | TChunk, string | T | Array<string | T>> : MessageValue extends V[K] ? V[K] | T : Extract<V[K], MessageValue>; };
|
|
106
|
+
type MessageKeys<V> = V extends unknown ? keyof V : never;
|
|
107
|
+
type TypedMessageValues<V extends MessageValues, T = string, TChunk = T> = (V extends unknown ? (values: ResolveMessageValues<V, T, TChunk>) => void : never) extends ((values: infer Values) => void) ? Values : never;
|
|
108
|
+
type MessageFormatArguments<V extends MessageValues, T = string, TChunk = T, Extra extends unknown[] = []> = MessageKeys<V> extends never ? [values?: Record<string, never>, ...extra: Extra] : {} extends TypedMessageValues<V, T, TChunk> ? [values?: TypedMessageValues<V, T, TChunk>, ...extra: Extra] : [values: TypedMessageValues<V, T, TChunk>, ...extra: Extra];
|
|
109
|
+
type UntypedMessageFormat = <T = void>(values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>) => string | T | (string | T)[];
|
|
110
|
+
type UntypedMessageFormatToParts = <T>(values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>) => MessageFormatPart<T>[];
|
|
111
|
+
type MessageFormatFunction<V extends MessageValues | undefined> = [V] extends [MessageValues] ? <T = string>(...args: MessageFormatArguments<Extract<V, MessageValues>, T>) => string | T | (string | T)[] : UntypedMessageFormat;
|
|
112
|
+
type MessageFormatToPartsFunction<V extends MessageValues | undefined> = [V] extends [MessageValues] ? <T = string>(...args: MessageFormatArguments<Extract<V, MessageValues>, T>) => MessageFormatPart<T>[] : UntypedMessageFormatToParts;
|
|
113
|
+
//#endregion
|
|
87
114
|
//#region packages/intl-messageformat/core.d.ts
|
|
88
115
|
export interface Options extends Omit<ParserOptions, "locale"> {
|
|
89
116
|
formatters?: Formatters;
|
|
90
117
|
}
|
|
91
|
-
export declare class IntlMessageFormat {
|
|
118
|
+
export declare class IntlMessageFormat<V extends MessageValues | undefined = undefined> {
|
|
92
119
|
private readonly ast;
|
|
93
120
|
private readonly locales;
|
|
94
121
|
private readonly resolvedLocale?;
|
|
@@ -97,8 +124,8 @@ export declare class IntlMessageFormat {
|
|
|
97
124
|
private readonly message;
|
|
98
125
|
private readonly formatterCache;
|
|
99
126
|
constructor(message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
|
|
100
|
-
format: <
|
|
101
|
-
formatToParts: <
|
|
127
|
+
format: MessageFormatFunction<V>;
|
|
128
|
+
formatToParts: MessageFormatToPartsFunction<V>;
|
|
102
129
|
resolvedOptions: () => {
|
|
103
130
|
locale: string;
|
|
104
131
|
};
|
|
@@ -139,5 +166,5 @@ export declare class MissingValueError extends FormatError {
|
|
|
139
166
|
constructor(variableId: string, originalMessage?: string);
|
|
140
167
|
}
|
|
141
168
|
//#endregion
|
|
142
|
-
export { IntlMessageFormat as default };
|
|
169
|
+
export { IntlMessageFormat as default, type MessageContract, type MessageFormatArguments, type MessageFormatFunction, type MessageFormatToPartsFunction, type MessageTag, type MessageValue, type MessageValues, type MessageValuesOf, type TypedMessageValues, type UntypedMessageContract };
|
|
143
170
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -215,7 +215,7 @@ var IntlMessageFormat = class IntlMessageFormat {
|
|
|
215
215
|
dateTime: {},
|
|
216
216
|
pluralRules: {}
|
|
217
217
|
};
|
|
218
|
-
this.format = (values) => {
|
|
218
|
+
this.format = ((values) => {
|
|
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) => {
|
|
@@ -225,8 +225,8 @@ var IntlMessageFormat = class IntlMessageFormat {
|
|
|
225
225
|
}, []);
|
|
226
226
|
if (result.length <= 1) return result[0] || "";
|
|
227
227
|
return result;
|
|
228
|
-
};
|
|
229
|
-
this.formatToParts = (values) => formatToParts(this.ast, this.locales, this.formatters, this.formats, values, void 0, this.message);
|
|
228
|
+
});
|
|
229
|
+
this.formatToParts = ((values) => formatToParts(this.ast, this.locales, this.formatters, this.formats, values, void 0, this.message));
|
|
230
230
|
this.resolvedOptions = () => ({ locale: this.resolvedLocale?.toString() || Intl.NumberFormat.supportedLocalesOf(this.locales)[0] });
|
|
231
231
|
this.getAst = () => this.ast;
|
|
232
232
|
this.locales = locales;
|
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":";;;A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B,KAAK,aAAa,mBAAmB,OAAO;GACrE,IAAI,iBAAiB,SAAS,GAC5B,OAAO,IAAI,KAAK,OAAO,iBAAiB,EAAE;GAG5C,OAAO,IAAI,KAAK,OAAO,OAAO,YAAY,WAAW,UAAU,QAAQ,EAAE;EAC3E;;;EAC2C,KAAA,UAAA;;;EAIjB,KAAA,UAAA;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"}
|
|
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\nimport type {\n MessageValues,\n MessageFormatFunction,\n MessageFormatToPartsFunction,\n UntypedMessageFormatToParts,\n} from '#packages/intl-messageformat/message-types.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 V extends MessageValues | undefined = undefined,\n> {\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 as UntypedMessageFormatToParts)<T>(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 }) as MessageFormatFunction<V>\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 )) as MessageFormatToPartsFunction<V>\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\nexport type {\n MessageValue,\n MessageTag,\n MessageValues,\n MessageContract,\n MessageValuesOf,\n UntypedMessageContract,\n TypedMessageValues,\n MessageFormatArguments,\n MessageFormatFunction,\n MessageFormatToPartsFunction,\n} from '#packages/intl-messageformat/message-types.js'\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,M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AAA,UAAA;;;EAIjB,KAAA,UAAA;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;;;ACxSA,IAAA,6BAAe"}
|
|
@@ -2698,7 +2698,7 @@ var IntlMessageFormat = class IntlMessageFormat {
|
|
|
2698
2698
|
dateTime: {},
|
|
2699
2699
|
pluralRules: {}
|
|
2700
2700
|
};
|
|
2701
|
-
this.format = (values) => {
|
|
2701
|
+
this.format = ((values) => {
|
|
2702
2702
|
const parts = this.formatToParts(values);
|
|
2703
2703
|
if (parts.length === 1) return parts[0].value;
|
|
2704
2704
|
const result = parts.reduce((all, part) => {
|
|
@@ -2708,8 +2708,8 @@ var IntlMessageFormat = class IntlMessageFormat {
|
|
|
2708
2708
|
}, []);
|
|
2709
2709
|
if (result.length <= 1) return result[0] || "";
|
|
2710
2710
|
return result;
|
|
2711
|
-
};
|
|
2712
|
-
this.formatToParts = (values) => formatToParts(this.ast, this.locales, this.formatters, this.formats, values, void 0, this.message);
|
|
2711
|
+
});
|
|
2712
|
+
this.formatToParts = ((values) => formatToParts(this.ast, this.locales, this.formatters, this.formats, values, void 0, this.message));
|
|
2713
2713
|
this.resolvedOptions = () => ({ locale: this.resolvedLocale?.toString() || Intl.NumberFormat.supportedLocalesOf(this.locales)[0] });
|
|
2714
2714
|
this.getAst = () => this.ast;
|
|
2715
2715
|
this.locales = locales;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-messageformat",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"globalization",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@formatjs/fast-memoize": "3.1.7",
|
|
38
|
-
"@formatjs/icu-messageformat-parser": "3.5.
|
|
38
|
+
"@formatjs/icu-messageformat-parser": "3.5.19"
|
|
39
39
|
}
|
|
40
40
|
}
|