{"_id":"@messageformat/parser","_rev":"3681633","name":"@messageformat/parser","description":"An AST parser for ICU MessageFormat strings","dist-tags":{"latest":"5.1.1"},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"}],"time":{"modified":"2025-02-13T05:44:06.000Z","created":"2020-11-29T17:18:22.650Z","5.1.1":"2024-12-28T18:37:25.371Z","5.1.0":"2023-06-08T14:21:16.212Z","5.0.0":"2021-05-13T12:03:16.131Z","5.0.0-beta.1":"2020-11-29T17:18:22.650Z"},"users":{},"repository":{"type":"git","url":"git+https://github.com/messageformat/messageformat.git","directory":"packages/parser"},"versions":{"5.1.1":{"name":"@messageformat/parser","version":"5.1.1","description":"An AST parser for ICU MessageFormat strings","keywords":["icu","messageformat","parser"],"contributors":[{"name":"Alex Sexton","email":"alexsexton@gmail.com"},{"name":"Eemeli Aro","email":"eemeli@gmail.com"},{"name":"Nikola Kovacs","email":"nikola.kovacs@gmail.com"},{"name":"Adrian Vogelsgesang","email":"adrian.vogelsgesang@tum.de"}],"license":"MIT","homepage":"http://messageformat.github.io/messageformat/api/parser/","repository":{"type":"git","url":"git+https://github.com/messageformat/messageformat.git","directory":"packages/parser"},"type":"commonjs","main":"lib/parser.js","exports":{".":"./lib/parser.js","./package.json":"./package.json"},"dependencies":{"moo":"^0.5.1"},"scripts":{"build":"tsc --project tsconfig.build.json","extract-api":"api-extractor run --verbose"},"_id":"@messageformat/parser@5.1.1","gitHead":"1ba1126d75610383fca20afc603aaba457ec420f","types":"./lib/parser.d.ts","bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"_nodeVersion":"23.4.0","_npmVersion":"10.9.2","dist":{"shasum":"ca7d6c18e9f3f6b6bc984a465dac16da00106055","size":8280,"noattachment":false,"key":"/@messageformat/parser/-/@messageformat/parser-5.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@messageformat/parser/download/@messageformat/parser-5.1.1.tgz"},"_npmUser":{"name":"eemeli","email":"eemeli@gmail.com"},"directories":{},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/parser_5.1.1_1735411045147_0.7911782426131801"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-12-28T18:37:25.371Z","publish_time":1735411045371,"_source_registry_name":"default","_cnpm_publish_time":1735411045371},"5.1.0":{"name":"@messageformat/parser","version":"5.1.0","description":"An AST parser for ICU MessageFormat strings","keywords":["icu","messageformat","parser"],"contributors":[{"name":"Alex Sexton","email":"alexsexton@gmail.com"},{"name":"Eemeli Aro","email":"eemeli@gmail.com"},{"name":"Nikola Kovacs","email":"nikola.kovacs@gmail.com"},{"name":"Adrian Vogelsgesang","email":"adrian.vogelsgesang@tum.de"}],"license":"MIT","homepage":"http://messageformat.github.io/messageformat/api/parser/","repository":{"type":"git","url":"git+https://github.com/messageformat/messageformat.git","directory":"packages/parser"},"type":"commonjs","main":"lib/parser.js","exports":{".":"./lib/parser.js","./package.json":"./package.json"},"dependencies":{"moo":"^0.5.1"},"scripts":{"build":"tsc --project tsconfig.build.json","extract-api":"api-extractor run --verbose"},"types":"./lib/parser.d.ts","gitHead":"04b395220c6f1327ede71fa5c888934ab8648e23","bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"_id":"@messageformat/parser@5.1.0","_nodeVersion":"19.8.1","_npmVersion":"9.5.1","dist":{"shasum":"05e4851c782d633ad735791dd0a68ee65d2a7201","size":8490,"noattachment":false,"key":"/@messageformat/parser/-/@messageformat/parser-5.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@messageformat/parser/download/@messageformat/parser-5.1.0.tgz"},"_npmUser":{"name":"eemeli","email":"eemeli@gmail.com"},"directories":{},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parser_5.1.0_1686234076038_0.7937263403291153"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-06-08T14:21:16.212Z","publish_time":1686234076212,"_source_registry_name":"default","_cnpm_publish_time":1686234076212},"5.0.0":{"name":"@messageformat/parser","version":"5.0.0","description":"An AST parser for ICU MessageFormat strings","keywords":["icu","messageformat","parser"],"contributors":[{"name":"Alex Sexton","email":"alexsexton@gmail.com"},{"name":"Eemeli Aro","email":"eemeli@gmail.com"},{"name":"Nikola Kovacs","email":"nikola.kovacs@gmail.com"},{"name":"Adrian Vogelsgesang","email":"adrian.vogelsgesang@tum.de"}],"license":"MIT","homepage":"http://messageformat.github.io/messageformat/api/parser/","repository":{"type":"git","url":"git+https://github.com/messageformat/messageformat.git","directory":"packages/parser"},"type":"commonjs","main":"lib/parser.js","exports":{".":"./lib/parser.js","./package.json":"./package.json"},"dependencies":{"moo":"^0.5.1"},"scripts":{"build":"tsc","extract-api":"api-extractor run --local --verbose"},"gitHead":"33ca9027809512d85bd7d212957afb85e7dd39c4","bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"_id":"@messageformat/parser@5.0.0","_nodeVersion":"15.11.0","_npmVersion":"lerna/3.22.1/node@v15.11.0+x64 (darwin)","dist":{"shasum":"5737e69d7d4a469998b527710f1891174fc1b262","size":10395,"noattachment":false,"key":"/@messageformat/parser/-/@messageformat/parser-5.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@messageformat/parser/download/@messageformat/parser-5.0.0.tgz"},"_npmUser":{"name":"eemeli","email":"eemeli@gmail.com"},"directories":{},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parser_5.0.0_1620907395952_0.5916850529124862"},"_hasShrinkwrap":false,"publish_time":1620907396131,"_cnpm_publish_time":1620907396131},"5.0.0-beta.1":{"name":"@messageformat/parser","version":"5.0.0-beta.1","description":"An AST parser for ICU MessageFormat strings","keywords":["icu","messageformat","parser"],"contributors":[{"name":"Alex Sexton","email":"alexsexton@gmail.com"},{"name":"Eemeli Aro","email":"eemeli@gmail.com"},{"name":"Nikola Kovacs","email":"nikola.kovacs@gmail.com"},{"name":"Adrian Vogelsgesang","email":"adrian.vogelsgesang@tum.de"}],"license":"MIT","homepage":"https://messageformat.github.io/","repository":{"type":"git","url":"git+https://github.com/messageformat/messageformat.git","directory":"packages/parser"},"type":"commonjs","main":"lib/parser.js","exports":{".":"./lib/parser.js","./package.json":"./package.json"},"dependencies":{"moo":"^0.5.1"},"scripts":{"build":"tsc","extract-api":"api-extractor run --local --verbose"},"gitHead":"af63ee0186c6f9ac2255da2ad476fd3d74cfa6ed","bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"_id":"@messageformat/parser@5.0.0-beta.1","_nodeVersion":"14.7.0","_npmVersion":"lerna/3.22.1/node@v14.7.0+x64 (darwin)","dist":{"shasum":"7349043edf517482d5e474635d071a56568d30c4","size":10305,"noattachment":false,"key":"/@messageformat/parser/-/@messageformat/parser-5.0.0-beta.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@messageformat/parser/download/@messageformat/parser-5.0.0-beta.1.tgz"},"_npmUser":{"name":"eemeli","email":"eemeli@gmail.com"},"directories":{},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parser_5.0.0-beta.1_1606670302412_0.33987941371842356"},"_hasShrinkwrap":false,"publish_time":1606670302650,"_cnpm_publish_time":1606670302650}},"readme":"# @messageformat/parser\n\nAn AST parser for [ICU MessageFormat] strings – part of [messageformat].\n\nThe `parse(src, [options])` function takes two parameters, first the\nstring to be parsed, and a second optional parameter `options`, an object with\nthe following possible keys:\n\n- `cardinal` and `ordinal` – Arrays of valid plural categories for the current\n  locale, used to validate `plural` and `selectordinal` keys. If these are\n  missing or set to false, the full set of valid [Unicode CLDR] keys is used:\n  `'zero', 'one', 'two', 'few', 'many', 'other'`. To disable this check, pass in\n  an empty array.\n\n- `strict` – By default, the parsing applies a few relaxations to the ICU\n  MessageFormat spec. Setting `strict: true` will disable these relaxations:\n  - The `argType` of `simpleArg` formatting functions will be restricted to the\n    set of `number`, `date`, `time`, `spellout`, `ordinal`, and `duration`,\n    rather than accepting any lower-case identifier that does not start with a\n    number.\n  - The optional `argStyle` of `simpleArg` formatting functions will not be\n    parsed as any other text, but instead as the spec requires: \"In\n    argStyleText, every single ASCII apostrophe begins and ends quoted literal\n    text, and unquoted {curly braces} must occur in matched pairs.\"\n  - Inside a `plural` or `selectordinal` statement, a pound symbol (`#`) is\n    replaced with the input number. By default, `#` is also parsed as a special\n    character in nested statements too, and can be escaped using apostrophes\n    (`'#'`). In strict mode `#` will be parsed as a special character only\n    directly inside a `plural` or `selectordinal` statement. Outside those, `#`\n    and `'#'` will be parsed as literal text.\n\nThe parser only supports the default `DOUBLE_OPTIONAL` [apostrophe mode], in\nwhich a single apostrophe only starts quoted literal text if it immediately\nprecedes a curly brace `{}`, or a pound symbol `#` if inside a plural format. A\nliteral apostrophe `'` is represented by either a single `'` or a doubled `''`\napostrophe character.\n\nThis package was previously named [messageformat-parser](https://www.npmjs.com/package/messageformat-parser).\n\n[icu messageformat]: https://messageformat.github.io/guide/\n[messageformat]: https://messageformat.github.io/\n[unicode cldr]: http://cldr.unicode.org/index/cldr-spec/plural-rules\n[apostrophe mode]: http://www.icu-project.org/apiref/icu4c/messagepattern_8h.html#af6e0757e0eb81c980b01ee5d68a9978b\n\n## Installation\n\n```sh\nnpm install @messageformat/parser\n```\n\n## Usage\n\n```js\n> const { parse } = require('@messageformat/parser')\n// For clarity, the examples below do not show the ctx object included for each token\n\n> parse('So {wow}.')\n[ { type: 'content', value: 'So ' },\n  { type: 'argument', arg: 'wow' },\n  { type: 'content', value: '.' } ]\n\n> parse('Such { thing }. { count, selectordinal, one {First} two {Second}' +\n        '                  few {Third} other {#th} } word.')\n[ { type: 'content', value: 'Such ' },\n  { type: 'argument', arg: 'thing' },\n  { type: 'content', value: '. ' },\n  { type: 'selectordinal',\n    arg: 'count',\n    cases: [\n      { key: 'one', tokens: [ { type: 'content', value: 'First' } ] },\n      { key: 'two', tokens: [ { type: 'content', value: 'Second' } ] },\n      { key: 'few', tokens: [ { type: 'content', value: 'Third' } ] },\n      { key: 'other',\n        tokens: [ { type: 'octothorpe' }, { type: 'content', value: 'th' } ] }\n    ] },\n  { type: 'content', value: ' word.' } ]\n\n> parse('Many{type,select,plural{ numbers}selectordinal{ counting}' +\n                         'select{ choices}other{ some {type}}}.')\n[ { type: 'content', value: 'Many' },\n  { type: 'select',\n    arg: 'type',\n    cases: [\n      { key: 'plural', tokens: [ { type: 'content', value: 'numbers' } ] },\n      { key: 'selectordinal', tokens: [ { type: 'content', value: 'counting' } ] },\n      { key: 'select', tokens: [ { type: 'content', value: 'choices' } ] },\n      { key: 'other',\n        tokens: [ { type: 'content', value: 'some ' }, { type: 'argument', arg: 'type' } ] }\n    ] },\n  { type: 'content', value: '.' } ]\n\n> parse('{Such compliance')\n// ParseError: invalid syntax at line 1 col 7:\n//\n//  {Such compliance\n//        ^\n\n> const msg = '{words, plural, zero{No words} one{One word} other{# words}}'\n> parse(msg)\n[ { type: 'plural',\n    arg: 'words',\n    cases: [\n      { key: 'zero', tokens: [ { type: 'content', value: 'No words' } ] },\n      { key: 'one', tokens: [ { type: 'content', value: 'One word' } ] },\n      { key: 'other',\n        tokens: [ { type: 'octothorpe' }, { type: 'content', value: ' words' } ] }\n    ] } ]\n\n> parse(msg, { cardinal: [ 'one', 'other' ], ordinal: [ 'one', 'two', 'few', 'other' ] })\n// ParseError: The plural case zero is not valid in this locale at line 1 col 17:\n//\n//   {words, plural, zero{\n//                   ^\n```\n\nFor more example usage, please take a look at our [test suite](src/parser.test.ts).\n\n## Structure\n\nThe output of `parse()` is an array of tokens, `Array<Content | PlainArg | FunctionArg | Select>`:\n\n<!-- prettier-ignore -->\n```typescript\ninterface Content {\n  type: 'content'\n  value: string\n  ctx: Context\n}\n\ninterface PlainArg {\n  type: 'argument'\n  arg: string\n  ctx: Context\n}\n\ninterface FunctionArg {\n  type: 'function'\n  arg: string\n  key: string\n  param?: Array<Content | PlainArg | FunctionArg | Select | Octothorpe>\n  ctx: Context\n}\n\ninterface Select {\n  type: 'plural' | 'select' | 'selectordinal'\n  arg: string\n  cases: Array<SelectCase>\n  pluralOffset?: number\n  ctx: Context\n}\n\ninterface SelectCase {\n  key: string\n  tokens: Array<Content | PlainArg | FunctionArg | Select | Octothorpe>\n  ctx: Context\n}\n\ninterface Octothorpe {\n  type: 'octothorpe'\n  ctx: Context\n}\n\ninterface Context {\n  offset: number\n  line: number\n  col: number\n  text: string\n  lineBreaks: number\n}\n```\n\n---\n\n[Messageformat](https://messageformat.github.io/) is an OpenJS Foundation project, and we follow its [Code of Conduct](https://code-of-conduct.openjsf.org/).\n\n<a href=\"https://openjsf.org\">\n<img width=200 alt=\"OpenJS Foundation\" src=\"https://messageformat.github.io/messageformat/logo/openjsf.svg\" />\n</a>\n","_attachments":{},"homepage":"http://messageformat.github.io/messageformat/api/parser/","bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"license":"MIT"}