{"id":18547,"library":"messageformat-parser","title":"messageformat-parser","description":"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.","status":"active","version":"4.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/messageformat/messageformat","tags":["javascript","icu","messageformat","parser"],"install":[{"cmd":"npm install messageformat-parser","lang":"bash","label":"npm"},{"cmd":"yarn add messageformat-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add messageformat-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The parser is a named export, not a default export. Use named import.","wrong":"import parse from 'messageformat-parser'","symbol":"parse","correct":"import { parse } from 'messageformat-parser'"},{"note":"PegParser is an alternative entry point for custom usage. Available since v4.","wrong":null,"symbol":"PegParser","correct":"import { PegParser } from 'messageformat-parser'"}],"quickstart":{"code":"import { parse } from 'messageformat-parser';\n\nconst ast = parse('You have {count, plural, one {# item} other {# items}}.');\nconsole.log(JSON.stringify(ast, null, 2));\n// Output shows parsed AST with type, plural, etc.","lang":"typescript","description":"Illustrates parsing an ICU MessageFormat string with plural arguments using messageformat-parser."},"warnings":[{"fix":"Use messageformat (the full package) for MF2 support, or continue using messageformat-parser for ICU MessageFormat.","message":"messageformat v4 switched to a new MF2 parser; this package is for legacy ICUMessageFormat only.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use messageformat or another library to format the AST into a string.","message":"The parser does not implement string interpolation or variable substitution; it only returns an AST.","severity":"gotcha","affected_versions":"all"},{"fix":"Update your code to use the new AST shape: 'type' property is string, not a number.","message":"parse() now returns a simpler AST in v4; check types for migration from v3.","severity":"deprecated","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install messageformat-parser' and ensure it's in your dependencies.","cause":"Package not installed or version mismatch.","error":"Cannot find module 'messageformat-parser'"},{"fix":"Check message format specification and escape single quotes with ''.","cause":"Invalid ICU message syntax, e.g., unescaped quotes or mismatched braces.","error":"SyntaxError: Expected \"{\" ..."},{"fix":"Use import { parse } from 'messageformat-parser' instead of importing default.","cause":"Importing default instead of named export.","error":"TypeError: parse is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}