{"bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"dist":{"shasum":"b824787f57fcda7d50769f5b63e8d4fda68f5b9e","tarball":"https://registry.npmjs.org/messageformat-parser/-/messageformat-parser-4.1.3.tgz","fileCount":6,"integrity":"sha512-2fU3XDCanRqeOCkn7R5zW5VQHWf+T3hH65SzuqRvjatBK7r4uyFa5mEX+k6F9Bd04LVM5G4/BHBTUJsOdW7uyg==","signatures":[{"sig":"MEYCIQCnYIYH1v3xhdl93zz8qWQPzATjs3HXjcNNOFLhK6PU8AIhAL6avJ0Rvp4hpjXKAOgC14zMF7dX5SHOTO/VcF2wS6wM","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":70035,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJekxMsCRA9TVsSAnZWagAAkIAQAKEuLGXgLGBE9Qu5iWNN\nDN1VdfBGLilR4d4w6I6M78HMGqrjAWUbuWCdECLMtrCMreC/5dl9xNjSsZTu\nK2vQNq46+cFrXIgehDvZSyfGk0Py7tWJVoflS7uFpYGkB9mTQE3ErmUlh1b9\nZeUSSNq6ZkNQTQKTH/TFIi+8QGywYLleYoU/ZrGE4kDEwvRgkkYFnjoxwMuH\n9GMWQ/c07TzlTtMtOFsTYLG+Er0rh3FgXdE8XeS8xgbrbnDoZGaXhmLDYRtl\nN2gB6cZqqEvDGY01fDhVZv9tNbTDzcFjVb/QPCSuGA3mxXVc81U2FJIGVamL\nnaSRzWQZhJT+Wdznq7GIaJ9YUVcaWExf1Bap9ss/EI6uChKzu8BaAh9SlA3b\nrU94YKsRHqQ6WCeFcCbcK4MVbP6xdU9rDewNOankpdkoCX0sCA3x4QipSINV\nUpmz4bnwotr2FsU1sYNwMP/gJU2vM9FcPu7vtl7CuOnpv4dKHMGpBzENdPIh\nGmmlbOkqtMqNfPoS1q4LP+L7nKrCni2EVHeZhbN/2VtghBJfmN708rOlPeey\ncX7z5FvRDukzc/WhzlICOeuCVqlPeH/qfCuWjOaG1vAKN7yoBllL/syRrVH8\nin/hvBm74o2WTXQyEx9ZMC/4scEl/OZ5YNmwINUhlazlgXpY3dApaGM+Ccik\noHGa\r\n=MUT4\r\n-----END PGP SIGNATURE-----\r\n"},"main":"parser.js","name":"messageformat-parser","readme":"# messageformat-parser\n\nA [PEG.js] parser for [ICU MessageFormat] strings – part of [messageformat].\nOutputs an AST defined by [parser.pegjs].\n\nThe generated `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\n[icu messageformat]: https://messageformat.github.io/guide/\n[messageformat]: https://messageformat.github.io/\n[parser.pegjs]: ./parser.pegjs\n[peg.js]: http://pegjs.org/\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> var parse = require('messageformat-parser').parse;\n\n> parse('So {wow}.')\n[ 'So ', { type: 'argument', arg: 'wow' }, '.' ]\n\n> parse('Such { thing }. { count, selectordinal, one {First} two {Second}' +\n        '                  few {Third} other {#th} } word.')\n[ 'Such ',\n  { type: 'argument', arg: 'thing' },\n  '. ',\n  { type: 'selectordinal',\n    arg: 'count',\n    offset: 0,\n    cases:\n     [ { key: 'one', tokens: [ 'First' ] },\n       { key: 'two', tokens: [ 'Second' ] },\n       { key: 'few', tokens: [ 'Third' ] },\n       { key: 'other', tokens: [ { type: 'octothorpe' }, 'th' ] } ] },\n  ' word.' ]\n\n> parse('Many{type,select,plural{ numbers}selectordinal{ counting}' +\n                         'select{ choices}other{ some {type}}}.')\n[ 'Many',\n  { type: 'select',\n    arg: 'type',\n    cases:\n     [ { key: 'plural', tokens: [ ' numbers' ] },\n       { key: 'selectordinal', tokens: [ ' counting' ] },\n       { key: 'select', tokens: [ ' choices' ] },\n       { key: 'other', tokens: [ ' some',\n                                 { type: 'argument', arg: 'type' } ] } ] },\n  '.' ]\n\n> parse('{Such compliance')\n// SyntaxError: Expected \",\", \"}\" or [ \\t\\n\\r] but \"c\" found.\n\n> var msg = '{words, plural, zero{No words} one{One word} other{# words}}';\n> var englishKeys = { cardinal: [ 'one', 'other' ],\n                      ordinal: [ 'one', 'two', 'few', 'other' ] };\n> parse(msg)\n[ { type: 'plural',\n    arg: 'words',\n    offset: 0,\n    cases:\n     [ { key: 'zero', tokens: [ 'No words' ] },\n       { key: 'one', tokens: [ 'One word' ] },\n       { key: 'other', tokens: [ { type: 'octothorpe' }, ' words' ] } ] } ]\n\n> parse(msg, englishKeys)\n// Error: Invalid key `zero` for argument `words`. Valid plural keys for this\n//        locale are `one`, `other`, and explicit keys like `=0`.\n```\n\nFor more example usage, please take a look at our [test suite](./test.js).\n\n## Structure\n\nThe output of `parse()` is a `Token` array:\n\n```typescript\ntype Token = string | Argument | Plural | Select | Function\n\ntype Argument = {\n  type: 'argument',\n  arg: Identifier\n}\n\ntype Plural = {\n  type: 'plural' | 'selectordinal',\n  arg: Identifier,\n  offset: number,\n  cases: PluralCase[]\n}\n\ntype Select = {\n  type: 'select',\n  arg: Identifier,\n  cases: SelectCase[]\n}\n\ntype Function = {\n  type: 'function',\n  arg: Identifier,\n  key: Identifier,\n  param: {\n    tokens: options.strict ? [string] : (Token | Octothorpe)[]\n  } | null\n}\n\ntype PluralCase = {\n  key: 'zero' | 'one' | 'two' | 'few' | 'many' | 'other' | '=0' | '=1' | '=2' | ...,\n  tokens: (Token | Octothorpe)[]\n}\n\ntype SelectCase = {\n  key: Identifier,\n  tokens: options.strict ? Token[] : (Token | Octothorpe)[]\n}\n\ntype Octothorpe = {\n  type: 'octothorpe'\n}\n\ntype Identifier = string  // not containing whitespace or control characters\n```\n\n---\n\n[Messageformat](https://messageformat.github.io/) is an OpenJS Foundation project, and we follow its [Code of Conduct](https://github.com/openjs-foundation/cross-project-council/blob/master/CODE_OF_CONDUCT.md).\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","gitHead":"dd10833d8d39155b005ea2ba6ec7a87f4daf0cd2","license":"MIT","scripts":{"test":"mocha","build":"pegjs parser.pegjs","prepublishOnly":"npm test"},"_npmUser":{"name":"eemeli","email":"eemeli@gmail.com"},"homepage":"https://messageformat.github.io/","keywords":["icu","messageformat","parser"],"repository":{"url":"git+https://github.com/messageformat/messageformat.git","type":"git","directory":"packages/parser"},"_npmVersion":"lerna/3.20.2/node@v13.10.1+x64 (darwin)","description":"A PEG.js parser for ICU MessageFormat strings","directories":{},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"},{"name":"slexaxton","email":"alexsexton@gmail.com"}],"_nodeVersion":"13.10.1","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"}],"eslintConfig":{"env":{"es6":true,"commonjs":true},"overrides":[{"env":{"mocha":true},"files":["test.js"],"rules":{"no-unused-vars":0}}]},"_hasShrinkwrap":false,"readmeFilename":"README.md","_npmOperationalInternal":{"tmp":"tmp/messageformat-parser_4.1.3_1586697003967_0.2938166965815976","host":"s3://npm-registry-packages"},"_id":"messageformat-parser@4.1.3","version":"4.1.3"}