{"_id":"@messageformat/parser@5.2.0","bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"dist":{"shasum":"8a476fadea25e1bb7835aaf806eb3f5ad2fb4f8a","tarball":"http://registry-npm.ywwl.com/@messageformat/parser/download/@messageformat/parser-5.2.0.tgz","fileCount":11,"integrity":"sha512-sc3hNZ0JtC32GhL5nUgPbh2ilcwji4G+Vmj/vhMd8hZaH//NDOvkfwKK1mFnRWG5h2DpksN8xr/HB5/+vMg3iw==","signatures":[{"sig":"MEYCIQCHTlwvU1up6Jky58+ZeJT9vyeWja97083VZakQkiRR7wIhAL6TIjoXK1Ty1UxMxui69BMI+IOnzAzA08g/+VR2ZO6D","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIAYTNWfUHJM4qTZZzKHXV/Zavh4LtL0RGLmOGI3I3RW6AiBhTtOgePYPLJIh2bKrgsJ/Y30zM6TjzHJ24tq9tv0Fyw=="}],"unpackedSize":44915,"size":8709,"noattachment":false,"key":"/@messageformat/parser/-/@messageformat/parser-5.2.0.tgz"},"main":"lib/parser.js","name":"@messageformat/parser","type":"commonjs","types":"./lib/parser.d.ts","exports":{".":{"import":"./esm/parser.js","default":"./lib/parser.js"},"./package.json":"./package.json"},"gitHead":"54f9f4a209addea4dac32f9efac610093223c417","license":"MIT","scripts":{"build":"npm run build:cjs && npm run build:esm","build:cjs":"tsc --project tsconfig.build.json --declaration --outDir lib","build:esm":"tsc --project tsconfig.build.json --module preserve --moduleResolution bundler --outDir esm","extract-api":"api-extractor run --verbose"},"version":"5.2.0","_npmUser":{"name":"eemeli","email":"eemeli@gmail.com"},"homepage":"http://messageformat.github.io/messageformat/api/parser/","keywords":["icu","messageformat","parser"],"repository":{"url":"git+https://github.com/messageformat/messageformat.git","type":"git","directory":"mf1/packages/parser"},"_npmVersion":"12.2.0","description":"An AST parser for ICU MessageFormat strings","directories":{},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"}],"_nodeVersion":"26.0.0","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"}],"dependencies":{"moo":"^0.5.1"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/parser_5.2.0_1791797285457_0.482255852533507"},"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","publish_time":1791797285541,"_cnpm_publish_time":1791797285541,"dist-tags":{"latest":"5.2.0"}}