{"bugs":{"url":"https://github.com/messageformat/parser/issues"},"dist":{"shasum":"7574d17228a7e024510f04728f710fa1630d5523","tarball":"https://registry.npmjs.org/messageformat-parser/-/messageformat-parser-3.0.0-beta.1.tgz","fileCount":5,"integrity":"sha512-N4/mXXj2/sOPYvSydAGCHJJ49FnxRYfjEEOF784FuGC13rSQ4GrmQoZG2GEaW99dRpmXzgm3dCD1FHFKGRbDhg==","signatures":[{"sig":"MEQCIChHl2F+D8+9LzrPZGMqz+NZdjALU3vE3tZceqC2OQRKAiBj1KbcsR+/qqVUOGPsFjLq3I+jHEonLZCm4BeC3nz+Pg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":59780},"main":"parser.js","name":"messageformat-parser","files":["parser.js","codemod-fix-backslash-escapes.js"],"readme":"# messageformat-parser  <a href=\"http://travis-ci.org/messageformat/parser\"><img align=\"right\" alt=\"Build Status\" src=\"https://secure.travis-ci.org/messageformat/parser.png\"></a>\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- `strictFunctionParams` – By default, function parameters are split on commas\n  and trimmed, so the parameters in `{x,fn,   a,   b   }` are parsed as\n  `['a','b']`. Setting `strictFunctionParams` to true will make the parser\n  follow the ICU MessageFormat spec more closely, and result in a params array\n  with a single element: `['   a,   b   ']`.\n\n- `strictNumberSign` – Inside a `plural` or `selectordinal` statement, a pound\n  symbol (`#`) is replaced with the input number. By default, `#` is also parsed\n  as a special character in nested statements too, and can be escaped using\n  apostrophes (`'#'`). Setting `strictNumberSign` to true will make the parser\n  follow the ICU MessageFormat spec more closely, and only parse `#` as a\n  special character directly inside a `plural` or `selectordinal` statement.\n  Outside those, `#` and `'#'` will be parsed as literal text.\n\nThe parser only supports the default `DOUBLE_OPTIONAL` [apostrophe mode]. A\nsingle apostrophe only starts quoted literal text if preceded by a curly brace\n(`{}`) or a pound symbol (`#`) inside a `plural` or `selectordinal` statement,\ndepending on the value of `strictNumberSign`. Otherwise, it is a literal\napostrophe. A double apostrophe is always a literal apostrophe.\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\n## Installation\n\n```sh\nnpm install messageformat-parser\n```\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\n## Structure\n\nThe output of `parse()` is a `Token` array:\n\n```js\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  params: string[]\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: strictNumberSign ? 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## License & Contributor License Agreement\nReleased under the MIT license. See the [messageformat README][CLA] for details.\n\n[CLA]: https://github.com/messageformat/messageformat.js#contributor-license-agreement\n","gitHead":"9b3ae2687cf72c2d58f6e1d5fb158247bb573af2","license":"MIT","scripts":{"test":"mocha","prepare":"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/parser.git","type":"git"},"_npmVersion":"5.6.0","description":"A PEG.js parser for ICU MessageFormat strings","directories":{},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"},{"name":"slexaxton","email":"alexsexton@gmail.com"}],"_nodeVersion":"9.5.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"}],"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"mocha":"^4.0.1","pegjs":"^0.10.0","expect.js":"^0.3.1"},"_npmOperationalInternal":{"tmp":"tmp/messageformat-parser_3.0.0-beta.1_1521290667546_0.3931494078752473","host":"s3://npm-registry-packages"},"_id":"messageformat-parser@3.0.0-beta.1","version":"3.0.0-beta.1"}