/** * What each node in a compiled message is, by the number it starts with. * * The numbers are the format, so a kind is only ever appended, never renumbered or reused. */ declare const Kind: { readonly Value: 0; readonly Number: 1; readonly DateTime: 2; readonly Plural: 3; readonly Ordinal: 4; readonly Select: 5; readonly Hash: 6; }; type Kind = (typeof Kind)[keyof typeof Kind]; /** * A compiled message. * * The CLI compiles a catalogue to this: strings and arrays, with styles already resolved to * `Intl` options. It is plain JSON, so it can cross a server/client boundary. * * A node is an array starting with its {@link Kind}; an array starting with anything else is a * concatenation. Operands are descriptor keys, never nodes. A message with no placeholders is its * own string. */ type Message$1 = string | Message$1[] | [typeof Kind.Value, string] | [typeof Kind.Number, string, Intl.NumberFormatOptions?, number?] | [typeof Kind.DateTime, string, Intl.DateTimeFormatOptions?] | [typeof Kind.Plural, string, Message$1.Cases, number?] | [typeof Kind.Ordinal, string, Message$1.Cases, number?] | [typeof Kind.Select, string, Message$1.Cases] | [typeof Kind.Hash]; declare namespace Message$1 { /** * A plural's or a select's branches, by key. A plural's keys are CLDR * categories or an exact `=n`, and `other` is the fallback for both. */ type Cases = { [key: string]: Message$1; }; /** What a compiled message is called with: the descriptor the transform built. */ type Values = Record; } /** * Compile one ICU MessageFormat 1 message. * * @param icu The message, in ICU MessageFormat 1 syntax * @returns The compiled message * @throws If the message is not valid ICU MessageFormat 1 */ export declare function compileMessage(icu: string): Message$1; export declare const AUTO_INCREMENT_IDENTIFIER: unique symbol; /** * The ICU case a branch is written as. * * Under `plural` and `ordinal` a number names an exact value, spelled `=0`, and * so is distinct from the CLDR category that would otherwise match it. `select` * has no such syntax, so a numeric key stays bare and matches both `0` and * `'0'`. * * Digits are read literally rather than coerced: `''`, `' '` and `'+0'` all * coerce to `=0`, which would pass for a key selecting zero and leave the * author's own key out of the catalogue. */ export declare function getBranchCase(kind: string, identifier: string | typeof AUTO_INCREMENT_IDENTIFIER): string; /** * Reject a branch key ICU cannot express, while the key is still attached to a * file and a line. * * A hyphenated string union is ordinary application code: it typechecks, * builds, and extracts to a normal-looking catalogue entry, and the only sign * of trouble is a parse error at format time. */ export declare function validateBranchIdentifier(kind: string, identifier: string | typeof AUTO_INCREMENT_IDENTIFIER): void; /** * Decides whether two placeholders sharing a name are the same placeholder, and * so may share it. Only the syntax that produced them can answer that, so the * caller supplies the comparison; by default nothing is interchangeable. */ export type PlaceholderEquivalence = (a: any, b: any) => boolean; export declare function assignSequenceIdentifiers(message: Message, sequence?: { current: number; }, equivalent?: PlaceholderEquivalence): void; /** * Argument styles: which ones a macro may author, and the `Intl` options each resolves to. * * Validation and compilation share these functions, so a style the transform accepts is one the * compiler honours. */ /** * The ICU argument types a macro can author, and the named styles each accepts. * * `currency` is absent from `number` because MF1 has nowhere to write the code; use * `::currency/EUR`. * `duration`, `spellout`, RBNF `ordinal` and `choice` are absent too, and compile to the bare * value. */ export declare const ARGUMENT_STYLES: { readonly number: readonly ['integer', 'percent']; readonly date: readonly ['short', 'medium', 'long', 'full']; readonly time: readonly ['short', 'medium', 'long', 'full']; }; export type ArgumentType = keyof typeof ARGUMENT_STYLES; export declare const ARGUMENT_TYPES: ArgumentType[]; export declare function isArgumentType(kind: string): kind is ArgumentType; /** The extra key a number's bag may carry, which `Intl` has no option for. */ export type NumberOptions = Intl.NumberFormatOptions & { scale?: number; }; /** A style that could not be resolved, with the reason it could not. */ export declare class StyleError extends Error {} /** * Turn a `date` or `time` argument style into `Intl.DateTimeFormat` options. * * A `::`-prefixed style is a skeleton such as `::yyyyMMdd`; an empty style takes MF1's default. * * @throws {StyleError} If the style names no fields */ export declare function dateTimeStyle(kind: 'date' | 'time', style: string): Intl.DateTimeFormatOptions; /** * Turn a `number` argument style into `Intl.NumberFormat` options. * * Accepts MF1's named styles, a `::`-prefixed skeleton, or a literal pattern such as `#,##0.00`. * Named styles are expanded here because the pattern parser would read `percent` as literal text. * * `scale` comes back beside the bag, since `Intl` has no option for it. * * @throws {StyleError} If the style is not valid, or asks for something `Intl` cannot express */ export declare function numberStyle(style: string): NumberOptions; /** * Reject an argument style the compiler cannot honour, while it is still attached to a file and * line. * * The compiler falls back to the default format, so an unchecked typo like `{d, date, meduim}` only * misformats in production. * Skeletons and patterns are checked by resolving them as the compiler will. */ export declare function validateArgumentStyle(type: ArgumentType, style: string): void; declare abstract class Base { toICUString(this: Message): string; toHashString(this: Message): string; } export declare class LiteralMessage extends Base { readonly text: string; constructor(text: string); } /** * An ICU argument type and style, e.g. `{n, number, percent}`. A style is * optional: `{n, number}` is the type's default formatting. * * Both are kept as the ICU strings they are written as, rather than as `Intl` * options, because the catalogue is the source of truth and only the ICU * spelling round-trips back out of it. */ export interface ArgumentFormat { type: ArgumentType; style?: string; } export declare class ArgumentMessage extends Base { identifier: string | typeof AUTO_INCREMENT_IDENTIFIER; readonly expression: any; readonly format?: ArgumentFormat | undefined; constructor(identifier: string | typeof AUTO_INCREMENT_IDENTIFIER, expression: any, format?: ArgumentFormat | undefined); } export declare class ElementMessage extends Base { identifier: string | typeof AUTO_INCREMENT_IDENTIFIER; readonly children: Message[]; readonly expression: any; constructor(identifier: string | typeof AUTO_INCREMENT_IDENTIFIER, children: Message[], expression: any); } export declare class ChoiceMessage extends Base { readonly kind: string; identifier: string | typeof AUTO_INCREMENT_IDENTIFIER; readonly branches: { identifier: string | typeof AUTO_INCREMENT_IDENTIFIER; readonly value: Message; }[]; readonly expression: any; /** * Subtracted from the selector before `#` is formatted, so "You and 2 * others" can select on a total of three. Only `plural` and `ordinal` * accept one; `select` has no number to offset. */ readonly offset?: number | undefined; constructor(kind: string, identifier: string | typeof AUTO_INCREMENT_IDENTIFIER, branches: { identifier: string | typeof AUTO_INCREMENT_IDENTIFIER; readonly value: Message; }[], expression: any, /** * Subtracted from the selector before `#` is formatted, so "You and 2 * others" can select on a total of three. Only `plural` and `ordinal` * accept one; `select` has no number to offset. */ offset?: number | undefined); } export declare class CompositeMessage extends Base { readonly descriptor: { id?: string; context?: string; }; readonly comments: string[]; readonly references: string[]; readonly children: Message[]; readonly accessor: any; readonly whitespace?: boolean | undefined; constructor(descriptor: { id?: string; context?: string; }, comments: string[], references: string[], children: Message[], accessor: any, whitespace?: boolean | undefined); } export type Message = LiteralMessage | ArgumentMessage | ElementMessage | ChoiceMessage | CompositeMessage; export declare function convertMessageToIcu(message: Message): string; /** * Quoting for text that has to survive a message format unchanged. * * This lives beside the converter rather than in a transform because it belongs * to the format being written, not the syntax being read: a literal is the same * literal whether it came from a template literal or from JSX. */ /** * Escape literal text so ICU MessageFormat 1 reads it as the text it is. * * MF1 escapes with an apostrophe: a run wrapped in one is taken literally, and a * doubled apostrophe is a single apostrophe. An apostrophe only opens a quoted * run when a character that needs quoting follows it, so `'#'` is a real escape * inside a plural and three literal characters anywhere else, which is why * `hash` has to be told rather than assumed. * * @param text Literal text as the author wrote it * @param hash Whether `#` stands for a number here, i.e. whether some `plural` * or `ordinal` encloses this text */ export declare function escapeIcuLiteral(text: string, hash?: boolean): string; /** * Hashed in userland rather than with `node:crypto`, because this runs wherever * a bundler runs it. `createHash` is one of the entry points `unenv` leaves * unimplemented, "[unenv] crypto.createHash is not implemented yet!", so a * plugin reaching for it throws in a Nitro or workerd build. The Web Crypto * equivalent, `subtle.digest`, is async, and an id is resolved from a * synchronous extraction pass. */ export declare function generateHash(input: string, context?: string): string; export {};