Unicode MessageFormat for JavaScript
    Preparing search index...

    Function parseMessage

    • Parse the source syntax representation of an MF2 message into its corresponding data model representation. Throws on syntax errors, but does not check for data model errors. To check for data model errors, use validate:

      import { MessageSyntaxError, parseMessage, validate } from 'messageformat';

      try {
      const msg = parseMessage('Hello {$world}');
      validate(msg);
      } catch (error) {
      if (error instanceof MessageSyntaxError) {
      // MessageDataModelError extends MessageSyntaxError
      ...
      }
      }

      Parameters

      • source: string

      Returns Model.Message