intl-messageformat

  • Version 12.1.3
  • Published
  • 118 kB
  • 2 dependencies
  • BSD-3-Clause license

Install

npm i intl-messageformat
yarn add intl-messageformat
pnpm add intl-messageformat

Overview

Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.

Index

Variables

variable formattedTextBrand

const formattedTextBrand: Symbol;

    variable messageTag

    const messageTag: Symbol;

      variable messageValues

      const messageValues: Symbol;

        Functions

        function formatToParts

        formatToParts: <T>(
        els: MessageFormatElement[],
        locales: string | string[],
        formatters: Formatters,
        formats: Formats,
        values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>,
        currentPluralValue?: number,
        originalMessage?: string
        ) => MessageFormatPart<T>[];

          function isFormatXMLElementFn

          isFormatXMLElementFn: <T>(
          el: PrimitiveType | T | FormatXMLElementFn<T>
          ) => el is FormatXMLElementFn<T, string | T | (string | T)[]>;

            Classes

            class FormatError

            class FormatError extends Error {}

              constructor

              constructor(msg: string, code: ErrorCode, originalMessage?: string);

                property code

                readonly code: ErrorCode;

                  property originalMessage

                  readonly originalMessage: string;
                  • Original message we're trying to format undefined if we're only dealing w/ AST

                    {(string | undefined)} FormatError

                  method toString

                  toString: () => string;

                    class IntlMessageFormat

                    class IntlMessageFormat<V extends MessageValues | undefined = undefined> {}

                      constructor

                      constructor(
                      message: string | MessageFormatElement[],
                      locales?: string | string[],
                      overrideFormats?: Partial<Formats>,
                      opts?: Options
                      );

                        property defaultLocale

                        static readonly defaultLocale: string;

                          property format

                          format:
                          | (<T = string>(
                          ...args: MessageFormatArguments<Extract<V, MessageValues>, T, T, []>
                          ) => string | T | (string | T)[])
                          | UntypedMessageFormat;

                            property formats

                            static formats: Formats;

                              property formatToParts

                              formatToParts:
                              | (<T = string>(
                              ...args: MessageFormatArguments<Extract<V, MessageValues>, T, T, []>
                              ) => MessageFormatPart<T>[])
                              | UntypedMessageFormatToParts;

                                property getAst

                                getAst: () => MessageFormatElement[];

                                  property resolvedOptions

                                  resolvedOptions: () => { locale: string };

                                    property resolveLocale

                                    static resolveLocale: (locales: string | string[]) => Intl.Locale | undefined;

                                      class InvalidValueError

                                      class InvalidValueError extends FormatError {}

                                        constructor

                                        constructor(
                                        variableId: string,
                                        value: any,
                                        options: string[],
                                        originalMessage?: string
                                        );

                                          class InvalidValueTypeError

                                          class InvalidValueTypeError extends FormatError {}

                                            constructor

                                            constructor(value: any, type: string, originalMessage?: string);

                                              class MissingValueError

                                              class MissingValueError extends FormatError {}

                                                constructor

                                                constructor(variableId: string, originalMessage?: string);

                                                  Interfaces

                                                  interface Formats

                                                  interface Formats {}

                                                    property date

                                                    date: Record<Format<'date'>, Intl.DateTimeFormatOptions>;

                                                      property number

                                                      number: Record<Format<'number'>, NumberFormatOptions>;

                                                        property time

                                                        time: Record<Format<'time'>, Intl.DateTimeFormatOptions>;

                                                          interface FormatterCache

                                                          interface FormatterCache {}

                                                            property dateTime

                                                            dateTime: Record<string, Intl.DateTimeFormat>;

                                                              property number

                                                              number: Record<string, NumberFormatOptions>;

                                                                property pluralRules

                                                                pluralRules: Record<string, Intl.PluralRules>;

                                                                  interface Formatters

                                                                  interface Formatters {}

                                                                    method getDateTimeFormat

                                                                    getDateTimeFormat: (
                                                                    locales?: string | string[],
                                                                    options?: Intl.DateTimeFormatOptions
                                                                    ) => Intl.DateTimeFormat;

                                                                      method getNumberFormat

                                                                      getNumberFormat: (
                                                                      locals?: string | string[],
                                                                      opts?: NumberFormatOptions
                                                                      ) => Intl.NumberFormat;

                                                                        method getPluralRules

                                                                        getPluralRules: (
                                                                        locales?: string | string[],
                                                                        options?: Intl.PluralRulesOptions
                                                                        ) => Intl.PluralRules;

                                                                          interface LiteralPart

                                                                          interface LiteralPart {}

                                                                            property type

                                                                            type: PART_TYPE.literal;

                                                                              property value

                                                                              value: string;

                                                                                interface MessageContract

                                                                                interface MessageContract<V extends MessageValues> {}
                                                                                • Type-only argument metadata shared by formatter integrations.

                                                                                property [messageValues]

                                                                                readonly [messageValues]: V;

                                                                                  interface MessageTag

                                                                                  interface MessageTag {}
                                                                                  • A tag placeholder whose callback type is supplied by the formatter.

                                                                                  property [messageTag]

                                                                                  readonly [messageTag]: true;

                                                                                    interface ObjectPart

                                                                                    interface ObjectPart<T = any> {}

                                                                                      property type

                                                                                      type: PART_TYPE.object;

                                                                                        property value

                                                                                        value: T;

                                                                                          interface Options

                                                                                          interface Options extends Omit<ParserOptions, 'locale'> {}

                                                                                            property formatters

                                                                                            formatters?: Formatters;

                                                                                              interface UntypedMessageContract

                                                                                              interface UntypedMessageContract {}

                                                                                                property [messageValues]

                                                                                                readonly [messageValues]?: never;

                                                                                                  Enums

                                                                                                  enum ErrorCode

                                                                                                  enum ErrorCode {
                                                                                                  MISSING_VALUE = 'MISSING_VALUE',
                                                                                                  INVALID_VALUE = 'INVALID_VALUE',
                                                                                                  MISSING_INTL_API = 'MISSING_INTL_API',
                                                                                                  }

                                                                                                    member INVALID_VALUE

                                                                                                    INVALID_VALUE = 'INVALID_VALUE'

                                                                                                      member MISSING_INTL_API

                                                                                                      MISSING_INTL_API = 'MISSING_INTL_API'

                                                                                                        member MISSING_VALUE

                                                                                                        MISSING_VALUE = 'MISSING_VALUE'

                                                                                                          enum PART_TYPE

                                                                                                          enum PART_TYPE {
                                                                                                          literal = 0,
                                                                                                          object = 1,
                                                                                                          }

                                                                                                            member literal

                                                                                                            literal = 0

                                                                                                              member object

                                                                                                              object = 1

                                                                                                                Type Aliases

                                                                                                                type FormattedText

                                                                                                                type FormattedText = string & {
                                                                                                                readonly [formattedTextBrand]: true;
                                                                                                                };
                                                                                                                • Formatter-produced text, including fallbacks; not a translation or safety guarantee.

                                                                                                                type FormatXMLElementFn

                                                                                                                type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (
                                                                                                                parts: Array<string | T>
                                                                                                                ) => R;

                                                                                                                  type MessageFormatArguments

                                                                                                                  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];

                                                                                                                    type MessageFormatFunction

                                                                                                                    type MessageFormatFunction<V extends MessageValues | undefined> = [V] extends [
                                                                                                                    MessageValues
                                                                                                                    ]
                                                                                                                    ? <T = string>(
                                                                                                                    ...args: MessageFormatArguments<Extract<V, MessageValues>, T>
                                                                                                                    ) => string | T | (string | T)[]
                                                                                                                    : UntypedMessageFormat;

                                                                                                                      type MessageFormatPart

                                                                                                                      type MessageFormatPart<T> = LiteralPart | ObjectPart<T>;

                                                                                                                        type MessageFormatToPartsFunction

                                                                                                                        type MessageFormatToPartsFunction<V extends MessageValues | undefined> = [
                                                                                                                        V
                                                                                                                        ] extends [MessageValues]
                                                                                                                        ? <T = string>(
                                                                                                                        ...args: MessageFormatArguments<Extract<V, MessageValues>, T>
                                                                                                                        ) => MessageFormatPart<T>[]
                                                                                                                        : UntypedMessageFormatToParts;

                                                                                                                          type MessageValue

                                                                                                                          type MessageValue = PrimitiveType;
                                                                                                                          • An unformatted ICU argument, before framework-specific rich values are added.

                                                                                                                          type MessageValues

                                                                                                                          type MessageValues = Record<string, MessageValue | MessageTag>;

                                                                                                                            type MessageValuesOf

                                                                                                                            type MessageValuesOf<D extends MessageContract<MessageValues>> =
                                                                                                                            D[typeof messageValues];

                                                                                                                              type NoMessageValues

                                                                                                                              type NoMessageValues = Record<never, never>;
                                                                                                                              • A message contract with no arguments.

                                                                                                                              type PrimitiveType

                                                                                                                              type PrimitiveType = string | number | bigint | boolean | null | undefined | Date;

                                                                                                                                type TypedMessageValues

                                                                                                                                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;

                                                                                                                                  Namespaces

                                                                                                                                  namespace global

                                                                                                                                  namespace global {}

                                                                                                                                    namespace global.FormatjsIntl

                                                                                                                                    namespace global.FormatjsIntl {}

                                                                                                                                      interface Formats

                                                                                                                                      interface Formats {}

                                                                                                                                        interface IntlConfig

                                                                                                                                        interface IntlConfig {}

                                                                                                                                          interface Message

                                                                                                                                          interface Message {}

                                                                                                                                            Package Files (1)

                                                                                                                                            Dependencies (2)

                                                                                                                                            Dev Dependencies (0)

                                                                                                                                            No dev dependencies.

                                                                                                                                            Peer Dependencies (0)

                                                                                                                                            No peer dependencies.

                                                                                                                                            Badge

                                                                                                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/intl-messageformat.

                                                                                                                                            • Markdown
                                                                                                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/intl-messageformat)
                                                                                                                                            • HTML
                                                                                                                                              <a href="https://www.jsdocs.io/package/intl-messageformat"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>