Registry / serialization / messageformat-parser

messageformat-parser

JSON →
library4.1.3jsnpmunverified

A PEG.js-based parser for ICU MessageFormat strings, used by the messageformat library to parse ICU message patterns into an AST. Current stable version is 4.1.3, with a release cadence aligned with the messageformat monorepo. Key differentiators: implements the ICUMessageFormat specification, supports plural, select, and complex patterns, and is the heritage parser before the shift to MF2 in messageformat v4. It is lightweight and focused solely on parsing.

npm install messageformat-parser
INSTALL
IMPORT
SIG · MESSAGEFORMAT-PARS
M
messageformat-parser
serializationjavascriptv4.1.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'messageformat-parser'
import parse from 'messageformat-parser'
The parser is a named export, not a default export. Use named import.
PegParser
import { PegParser } from 'messageformat-parser'
PegParser is an alternative entry point for custom usage. Available since v4.

Illustrates parsing an ICU MessageFormat string with plural arguments using messageformat-parser.

import { parse } from 'messageformat-parser'; const ast = parse('You have {count, plural, one {# item} other {# items}}.'); console.log(JSON.stringify(ast, null, 2)); // Output shows parsed AST with type, plural, etc.
Debug
Known issues
breakingmessageformat v4 switched to a new MF2 parser; this package is for legacy ICUMessageFormat only.
fix
Use messageformat (the full package) for MF2 support, or continue using messageformat-parser for ICU MessageFormat.
affects: >=4.0.0
gotchaThe parser does not implement string interpolation or variable substitution; it only returns an AST.
fix
Use messageformat or another library to format the AST into a string.
affects: all
deprecatedparse() now returns a simpler AST in v4; check types for migration from v3.
fix
Update your code to use the new AST shape: 'type' property is string, not a number.
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find module 'messageformat-parser'
Package not installed or version mismatch.
fix
Run 'npm install messageformat-parser' and ensure it's in your dependencies.
SyntaxError: Expected "{" ...
Invalid ICU message syntax, e.g., unescaped quotes or mismatched braces.
fix
Check message format specification and escape single quotes with ''.
TypeError: parse is not a function
Importing default instead of named export.
fix
Use import { parse } from 'messageformat-parser' instead of importing default.
Upgrade
Version history
4.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
messageformat-parser — npm install messageformat-parser · libregistry