intl-messageformat-parser

  • Version 6.4.4
  • Published
  • 306 kB
  • 2 dependencies
  • BSD-3-Clause license

Install

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

Overview

Parses ICU Message strings into an AST via JavaScript.

Index

Variables

variable pegParse

const pegParse: ParseFunction;

    Functions

    function createLiteralElement

    createLiteralElement: (value: string) => LiteralElement;

      function createNumberElement

      createNumberElement: (value: string, style?: string | null) => NumberElement;

        function isArgumentElement

        isArgumentElement: (el: MessageFormatElement) => el is ArgumentElement;

          function isDateElement

          isDateElement: (el: MessageFormatElement) => el is DateElement;

            function isDateTimeSkeleton

            isDateTimeSkeleton: (
            el?: DateElement['style'] | TimeElement['style'] | Skeleton
            ) => el is DateTimeSkeleton;

              function isLiteralElement

              isLiteralElement: (el: MessageFormatElement) => el is LiteralElement;
              • Type Guards

              function isNumberElement

              isNumberElement: (el: MessageFormatElement) => el is NumberElement;

                function isNumberSkeleton

                isNumberSkeleton: (
                el: NumberElement['style'] | Skeleton
                ) => el is NumberSkeleton;

                  function isPluralElement

                  isPluralElement: (el: MessageFormatElement) => el is PluralElement;

                    function isPoundElement

                    isPoundElement: (el: MessageFormatElement) => el is PoundElement;

                      function isSelectElement

                      isSelectElement: (el: MessageFormatElement) => el is SelectElement;

                        function isTagElement

                        isTagElement: (el: MessageFormatElement) => el is TagElement;

                          function isTimeElement

                          isTimeElement: (el: MessageFormatElement) => el is TimeElement;

                            function parse

                            parse: (input: string, opts?: ParseOptions) => MessageFormatElement[];

                              Classes

                              class SyntaxError

                              class SyntaxError extends Error {}

                                constructor

                                constructor(
                                message: string,
                                expected: Expectation[],
                                found: string,
                                location: IFileRange
                                );

                                  property expected

                                  expected: Expectation[];

                                    property found

                                    found: string;

                                      property location

                                      location: IFileRange;

                                        property message

                                        message: string;

                                          property name

                                          name: string;

                                            method buildMessage

                                            static buildMessage: (expected: Expectation[], found: string | null) => string;

                                              Interfaces

                                              interface BaseElement

                                              interface BaseElement<T extends TYPE> {}

                                                property location

                                                location?: Location;

                                                  property type

                                                  type: T;

                                                    property value

                                                    value: string;

                                                      interface DateTimeSkeleton

                                                      interface DateTimeSkeleton {}

                                                        property location

                                                        location?: Location;

                                                          property parsedOptions

                                                          parsedOptions: Intl.DateTimeFormatOptions;

                                                            property pattern

                                                            pattern: string;

                                                              property type

                                                              type: SKELETON_TYPE.dateTime;

                                                                interface ExtendedNumberFormatOptions

                                                                interface ExtendedNumberFormatOptions extends NumberFormatOptions {}

                                                                  property scale

                                                                  scale?: number;

                                                                    interface IAnyExpectation

                                                                    interface IAnyExpectation {}

                                                                      property type

                                                                      type: 'any';

                                                                        interface IClassExpectation

                                                                        interface IClassExpectation {}

                                                                          property ignoreCase

                                                                          ignoreCase: boolean;

                                                                            property inverted

                                                                            inverted: boolean;

                                                                              property parts

                                                                              parts: IClassParts;

                                                                                property type

                                                                                type: 'class';

                                                                                  interface IClassParts

                                                                                  interface IClassParts extends Array<string | IClassParts> {}

                                                                                    interface IEndExpectation

                                                                                    interface IEndExpectation {}

                                                                                      property type

                                                                                      type: 'end';

                                                                                        interface IFilePosition

                                                                                        interface IFilePosition {}

                                                                                          property column

                                                                                          column: number;

                                                                                            property line

                                                                                            line: number;

                                                                                              property offset

                                                                                              offset: number;

                                                                                                interface IFileRange

                                                                                                interface IFileRange {}

                                                                                                  property end

                                                                                                  end: IFilePosition;

                                                                                                    property start

                                                                                                    start: IFilePosition;

                                                                                                      interface ILiteralExpectation

                                                                                                      interface ILiteralExpectation {}

                                                                                                        property ignoreCase

                                                                                                        ignoreCase: boolean;

                                                                                                          property text

                                                                                                          text: string;

                                                                                                            property type

                                                                                                            type: 'literal';

                                                                                                              interface IOtherExpectation

                                                                                                              interface IOtherExpectation {}

                                                                                                                property description

                                                                                                                description: string;

                                                                                                                  property type

                                                                                                                  type: 'other';

                                                                                                                    interface IParseOptions

                                                                                                                    interface IParseOptions {}

                                                                                                                      property filename

                                                                                                                      filename?: string;

                                                                                                                        property startRule

                                                                                                                        startRule?: string;

                                                                                                                          property tracer

                                                                                                                          tracer?: any;

                                                                                                                            index signature

                                                                                                                            [key: string]: any;

                                                                                                                              interface Location

                                                                                                                              interface Location {}

                                                                                                                                property end

                                                                                                                                end: LocationDetails;

                                                                                                                                  property start

                                                                                                                                  start: LocationDetails;

                                                                                                                                    interface LocationDetails

                                                                                                                                    interface LocationDetails {}

                                                                                                                                      property column

                                                                                                                                      column: number;

                                                                                                                                        property line

                                                                                                                                        line: number;

                                                                                                                                          property offset

                                                                                                                                          offset: number;

                                                                                                                                            interface NumberSkeleton

                                                                                                                                            interface NumberSkeleton {}

                                                                                                                                              property location

                                                                                                                                              location?: Location;

                                                                                                                                                property parsedOptions

                                                                                                                                                parsedOptions: ExtendedNumberFormatOptions;

                                                                                                                                                  property tokens

                                                                                                                                                  tokens: NumberSkeletonToken[];

                                                                                                                                                    property type

                                                                                                                                                    type: SKELETON_TYPE.number;

                                                                                                                                                      interface NumberSkeletonToken

                                                                                                                                                      interface NumberSkeletonToken {}

                                                                                                                                                        property options

                                                                                                                                                        options: string[];

                                                                                                                                                          property stem

                                                                                                                                                          stem: string;

                                                                                                                                                            interface Options

                                                                                                                                                            interface Options {}

                                                                                                                                                              property captureLocation

                                                                                                                                                              captureLocation?: boolean;
                                                                                                                                                              • Capture location info in AST Default is false

                                                                                                                                                              property ignoreTag

                                                                                                                                                              ignoreTag?: boolean;
                                                                                                                                                              • Whether to treat HTML/XML tags as string literal instead of parsing them as tag token. When this is false we only allow simple tags without any attributes

                                                                                                                                                              property normalizeHashtagInPlural

                                                                                                                                                              normalizeHashtagInPlural?: boolean;
                                                                                                                                                              • Whether to convert # in plural rule options to {var, number} Default is true

                                                                                                                                                              property shouldParseSkeletons

                                                                                                                                                              shouldParseSkeletons?: boolean;
                                                                                                                                                              • Whether to parse number/datetime skeleton into Intl.NumberFormatOptions & Intl.DateTimeFormatOptions

                                                                                                                                                              interface PluralElement

                                                                                                                                                              interface PluralElement extends BaseElement<TYPE.plural> {}

                                                                                                                                                                property offset

                                                                                                                                                                offset: number;

                                                                                                                                                                  property options

                                                                                                                                                                  options: Record<ValidPluralRule, PluralOrSelectOption>;

                                                                                                                                                                    property pluralType

                                                                                                                                                                    pluralType: Intl.PluralRulesOptions['type'];

                                                                                                                                                                      interface PluralOrSelectOption

                                                                                                                                                                      interface PluralOrSelectOption {}

                                                                                                                                                                        property location

                                                                                                                                                                        location?: Location;

                                                                                                                                                                          property value

                                                                                                                                                                          value: MessageFormatElement[];

                                                                                                                                                                            interface PoundElement

                                                                                                                                                                            interface PoundElement {}

                                                                                                                                                                              property location

                                                                                                                                                                              location?: Location;

                                                                                                                                                                                property type

                                                                                                                                                                                type: TYPE.pound;

                                                                                                                                                                                  interface SelectElement

                                                                                                                                                                                  interface SelectElement extends BaseElement<TYPE.select> {}

                                                                                                                                                                                    property options

                                                                                                                                                                                    options: Record<string, PluralOrSelectOption>;

                                                                                                                                                                                      interface SelectOption

                                                                                                                                                                                      interface SelectOption {}

                                                                                                                                                                                        property id

                                                                                                                                                                                        id: string;

                                                                                                                                                                                          property location

                                                                                                                                                                                          location?: Location;

                                                                                                                                                                                            property value

                                                                                                                                                                                            value: MessageFormatElement[];

                                                                                                                                                                                              interface SimpleFormatElement

                                                                                                                                                                                              interface SimpleFormatElement<T extends TYPE, S extends Skeleton>
                                                                                                                                                                                              extends BaseElement<T> {}

                                                                                                                                                                                                property style

                                                                                                                                                                                                style?: string | S | null;

                                                                                                                                                                                                  interface TagElement

                                                                                                                                                                                                  interface TagElement {}

                                                                                                                                                                                                    property children

                                                                                                                                                                                                    children: MessageFormatElement[];

                                                                                                                                                                                                      property location

                                                                                                                                                                                                      location?: Location;

                                                                                                                                                                                                        property type

                                                                                                                                                                                                        type: TYPE.tag;

                                                                                                                                                                                                          property value

                                                                                                                                                                                                          value: string;

                                                                                                                                                                                                            Enums

                                                                                                                                                                                                            enum SKELETON_TYPE

                                                                                                                                                                                                            enum SKELETON_TYPE {
                                                                                                                                                                                                            number = 0,
                                                                                                                                                                                                            dateTime = 1,
                                                                                                                                                                                                            }

                                                                                                                                                                                                              member dateTime

                                                                                                                                                                                                              dateTime = 1

                                                                                                                                                                                                                member number

                                                                                                                                                                                                                number = 0

                                                                                                                                                                                                                  enum TYPE

                                                                                                                                                                                                                  enum TYPE {
                                                                                                                                                                                                                  literal = 0,
                                                                                                                                                                                                                  argument = 1,
                                                                                                                                                                                                                  number = 2,
                                                                                                                                                                                                                  date = 3,
                                                                                                                                                                                                                  time = 4,
                                                                                                                                                                                                                  select = 5,
                                                                                                                                                                                                                  plural = 6,
                                                                                                                                                                                                                  pound = 7,
                                                                                                                                                                                                                  tag = 8,
                                                                                                                                                                                                                  }

                                                                                                                                                                                                                    member argument

                                                                                                                                                                                                                    argument = 1
                                                                                                                                                                                                                    • Variable w/o any format, e.g var in this is a {var}

                                                                                                                                                                                                                    member date

                                                                                                                                                                                                                    date = 3
                                                                                                                                                                                                                    • Variable w/ date format

                                                                                                                                                                                                                    member literal

                                                                                                                                                                                                                    literal = 0
                                                                                                                                                                                                                    • Raw text

                                                                                                                                                                                                                    member number

                                                                                                                                                                                                                    number = 2
                                                                                                                                                                                                                    • Variable w/ number format

                                                                                                                                                                                                                    member plural

                                                                                                                                                                                                                    plural = 6
                                                                                                                                                                                                                    • Variable w/ plural format

                                                                                                                                                                                                                    member pound

                                                                                                                                                                                                                    pound = 7
                                                                                                                                                                                                                    • Only possible within plural argument. This is the # symbol that will be substituted with the count.

                                                                                                                                                                                                                    member select

                                                                                                                                                                                                                    select = 5
                                                                                                                                                                                                                    • Variable w/ select format

                                                                                                                                                                                                                    member tag

                                                                                                                                                                                                                    tag = 8
                                                                                                                                                                                                                    • XML-like tag

                                                                                                                                                                                                                    member time

                                                                                                                                                                                                                    time = 4
                                                                                                                                                                                                                    • Variable w/ time format

                                                                                                                                                                                                                    Type Aliases

                                                                                                                                                                                                                    type ArgumentElement

                                                                                                                                                                                                                    type ArgumentElement = BaseElement<TYPE.argument>;

                                                                                                                                                                                                                      type DateElement

                                                                                                                                                                                                                      type DateElement = SimpleFormatElement<TYPE.date, DateTimeSkeleton>;

                                                                                                                                                                                                                        type Expectation

                                                                                                                                                                                                                        type Expectation =
                                                                                                                                                                                                                        | ILiteralExpectation
                                                                                                                                                                                                                        | IClassExpectation
                                                                                                                                                                                                                        | IAnyExpectation
                                                                                                                                                                                                                        | IEndExpectation
                                                                                                                                                                                                                        | IOtherExpectation;

                                                                                                                                                                                                                          type LiteralElement

                                                                                                                                                                                                                          type LiteralElement = BaseElement<TYPE.literal>;

                                                                                                                                                                                                                            type MessageFormatElement

                                                                                                                                                                                                                            type MessageFormatElement =
                                                                                                                                                                                                                            | LiteralElement
                                                                                                                                                                                                                            | ArgumentElement
                                                                                                                                                                                                                            | NumberElement
                                                                                                                                                                                                                            | DateElement
                                                                                                                                                                                                                            | TimeElement
                                                                                                                                                                                                                            | SelectElement
                                                                                                                                                                                                                            | PluralElement
                                                                                                                                                                                                                            | TagElement
                                                                                                                                                                                                                            | PoundElement;

                                                                                                                                                                                                                              type NumberElement

                                                                                                                                                                                                                              type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>;

                                                                                                                                                                                                                                type ParseFunction

                                                                                                                                                                                                                                type ParseFunction = (
                                                                                                                                                                                                                                input: string,
                                                                                                                                                                                                                                options?: IParseOptions
                                                                                                                                                                                                                                ) => MessageFormatElement[];

                                                                                                                                                                                                                                  type ParseOptions

                                                                                                                                                                                                                                  type ParseOptions = Options & IParseOptions;

                                                                                                                                                                                                                                    type Skeleton

                                                                                                                                                                                                                                    type Skeleton = NumberSkeleton | DateTimeSkeleton;

                                                                                                                                                                                                                                      type TimeElement

                                                                                                                                                                                                                                      type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>;

                                                                                                                                                                                                                                        type ValidPluralRule

                                                                                                                                                                                                                                        type ValidPluralRule = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other' | string;

                                                                                                                                                                                                                                          Package Files (3)

                                                                                                                                                                                                                                          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-parser.

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