UNPKG

@messageformat/icu-messageformat-1

Version:

Compile ICU MessageFormat 1 sources into MessageFormat 2 formatters

50 lines (49 loc) 1.63 kB
import type * as AST from '@messageformat/parser'; import type { Model as MF } from 'messageformat'; /** * Convert an ICU MessageFormat 1 message into a {@link MF.Message | Model.Message} data object. * * If the source message contains any inner selectors, they will be * lifted into a single top-level selector. * * Only literal values are supported in formatter parameters. * Any unsupported `argStyle` value will be included as a {@link MF.Options | Model.Options} value. * * ```js * import { mf1ToMessageData, mf1Validate } from '@messageformat/icu-messageformat-1'; * import { parse } from '@messageformat/parser'; * * const mf1Msg = parse('The total is {V, number, ::currency/EUR}.'); * const mf2Msg = mf1ToMessageData(mf1Msg); * mf1Validate(mf2Msg); * mf2msg; * ``` * * ```js * { * type: 'message', * declarations: [], * pattern: [ * 'The total is ', * { * type: 'expression', * arg: { type: 'variable', name: 'V' }, * functionRef: { * type: 'function', * name: 'mf1:currency', * options: Map(1) { 'currency' => { type: 'literal', value: 'EUR' } } * }, * attributes: Map(2) { * 'mf1:argType' => { type: 'literal', value: 'number' }, * 'mf1:argStyle' => { type: 'literal', value: '::currency/EUR' } * } * }, * '.' * ] * } * ``` * * @param ast - An ICU MessageFormat message as an array of `@messageformat/parser` * {@link https://messageformat.github.io/messageformat/api/parser.parse/ | AST tokens}. */ export declare function mf1ToMessageData(ast: AST.Token[]): MF.Message;