Skip to main content
Version: 1.2.10

parseMessagePattern

Parses a message string, producing code that can be evaluated multiple times against different arguments.

Syntax

parseMessagePattern(message: string, matcher: MessageMatcher): MessageCode;

Parameters

  • message: string
    • Message string to parse
  • matcher: MessageMatcher
    • Matcher to reuse across multiple parses

Example

import { buildMessageMatcher, parseMessagePattern } from '@phensley/messageformat';

const matcher = buildMessageMatcher(['foo']);

json(parseMessagePattern('{0 foo}', matcher));
[6,"foo",[0],[]]
json(parseMessagePattern('{0 plural one {# item} other {# items}}', matcher));
[2,[0],0,0,[[1,"one",[4,[[7],[0," item"]]]],[1,"other",[4,[[7],[0," items"]]]]]]

References