{"_id":"@cjser/jsdoc-type-pratt-parser__v9_1_2","name":"@cjser/jsdoc-type-pratt-parser__v9_1_2","dist-tags":{"latest":"9.1.2-cjser.2"},"versions":{"9.1.2-cjser.2":{"name":"@cjser/jsdoc-type-pratt-parser__v9_1_2","version":"9.1.2-cjser.2","description":"[![Npm Package](https://badgen.net/npm/v/jsdoc-type-pratt-parser)](https://www.npmjs.com/package/jsdoc-type-pratt-parser) [![Test Status](https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/actions/workflows/test.yml/badge.svg?branch=main)]","type":"module","types":"./dist/index.d.mts","exports":{".":{"require":"./dist-cjser/index.cjs","default":"./dist/index.mjs"},"./package.json":"./package.json"},"directories":{"test":"test"},"scripts":{"test":"npm run typecheck && npm run lint && npm run test:spec","test:spec":"mocha","test:coverage":"c8 --all npm run test:spec","test:coveralls":"c8 report --reporter=lcov && coveralls","lint":"eslint .","typecheck":"tsc --noEmit","attw":"attw --pack . --profile esm-only","build":"tsdown && npm run attw","apidoc":"typedoc --options typedoc.json","preversion":"npm test","semantic-release":"semantic-release","benchmark":"npm run build && node benchmark/benchmark.js","upgrade":"npm-upgrade"},"author":{"name":"Simon Seyock","url":"https://github.com/simonseyock"},"contributors":[{"name":"Brett Zamir"}],"license":"MIT","engines":{"node":"^22.22.2 || >=24.15.0"},"dependencies":{"@types/estree":"^1.0.9"},"devDependencies":{"@arethetypeswrong/cli":"^0.18.5","@es-joy/escodegen":"^4.2.0","@semantic-release/changelog":"^7.0.0","@semantic-release/git":"^11.0.1","@types/chai":"^5.2.3","@types/mocha":"^10.0.10","@types/node":"^26.2.0","@types/sinon":"^22.0.0","@types/sinon-chai":"^4.0.0","@typescript-eslint/eslint-plugin":"^8.42.0","benchmark":"^2.1.4","c8":"^12.0.0","catharsis":"^0.11.0","chai":"^6.2.2","coveralls":"^3.1.1","eslint":"^9.39.4","eslint-config-love":"154.1.0","eslint-plugin-import":"^2.32.0","eslint-plugin-n":"^18.3.0","eslint-plugin-promise":"^7.3.0","espree":"^11.2.0","jsdoctypeparser":"^9.0.0","mocha":"^11.8.0","npm-upgrade":"^3.3.0","patch-package":"^8.0.1","semantic-release":"^25.0.9","sinon":"^22.1.0","sinon-chai":"^4.0.1","ts-node":"^10.9.2","tsdown":"^0.22.14","typedoc":"^0.28.20","typedoc-plugin-merge-modules":"^7.0.0","typescript":"^6.0.3"},"ts-standard":{"ignore":["/submodules/","/build/","/pages/"]},"repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"bugs":{"url":"https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues"},"homepage":"https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser","keywords":["jsdoc","pratt","parser"],"release":{"branches":["main",{"name":"dev","prerelease":true}],"plugins":["@semantic-release/commit-analyzer","@semantic-release/github","@semantic-release/npm","@semantic-release/release-notes-generator","@semantic-release/changelog","@semantic-release/git"]},"publishConfig":{"access":"public"},"main":"./dist-cjser/index.cjs","cjser":{"sourceVersion":"9.1.2","cjserVersion":2,"original":{"name":"jsdoc-type-pratt-parser","version":"9.1.2","exports":{".":"./dist/index.mjs","./package.json":"./package.json"},"repository":{"type":"git","url":"https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser.git"},"dependencies":{"@types/estree":"^1.0.9"},"files":["dist/**/*"],"scripts":{"test":"npm run typecheck && npm run lint && npm run test:spec","test:spec":"mocha","test:coverage":"c8 --all npm run test:spec","test:coveralls":"c8 report --reporter=lcov && coveralls","lint":"eslint .","typecheck":"tsc --noEmit","attw":"attw --pack . --profile esm-only","build":"tsdown && npm run attw","apidoc":"typedoc --options typedoc.json","preversion":"npm test","prepublishOnly":"npm run build","semantic-release":"semantic-release","benchmark":"npm run build && node benchmark/benchmark.js","upgrade":"npm-upgrade"}}},"gitHead":"a4bef54d7d22d3d9a6b84528457938d84cd65fe7","_id":"@cjser/jsdoc-type-pratt-parser__v9_1_2@9.1.2-cjser.2","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-mSvWRM5T2/yulZhKhPyJJvQcwxYtVpxrA1RCwlAhDGxhCjD2V0kAzPbjfJDBQS2KGK6/Agj0lcQpM7CSyMImUA==","shasum":"e0924a80859bd0b44743f2d7b7c6364246e3641e","tarball":"https://registry.npmjs.org/@cjser/jsdoc-type-pratt-parser__v9_1_2/-/jsdoc-type-pratt-parser__v9_1_2-9.1.2-cjser.2.tgz","fileCount":6,"unpackedSize":249903,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIFiAVINzTEbcIKWnvmGlnLJXVlcvgI1RC+rAZnG3VLrcAiByLrEFueuFhAV4azOabStE13/necSyC/75zeRAmuWQEQ=="}]},"_npmUser":{"name":"nanahira","email":"nanahira@momobako.com"},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jsdoc-type-pratt-parser__v9_1_2_9.1.2-cjser.2_1788288838369_0.6142360237979574"},"_hasShrinkwrap":false}},"time":{"created":"2026-09-01T18:53:58.019Z","9.1.2-cjser.2":"2026-09-01T18:53:58.518Z","modified":"2026-09-01T18:53:58.817Z"},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"description":"[![Npm Package](https://badgen.net/npm/v/jsdoc-type-pratt-parser)](https://www.npmjs.com/package/jsdoc-type-pratt-parser) [![Test Status](https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/actions/workflows/test.yml/badge.svg?branch=main)]","homepage":"https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser","keywords":["jsdoc","pratt","parser"],"repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"contributors":[{"name":"Brett Zamir"}],"author":{"name":"Simon Seyock","url":"https://github.com/simonseyock"},"bugs":{"url":"https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues"},"license":"MIT","readme":"[![Npm Package](https://badgen.net/npm/v/jsdoc-type-pratt-parser)](https://www.npmjs.com/package/jsdoc-type-pratt-parser)\n[![Test Status](https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/actions?query=branch%3Amain)\n[![Coverage Status](https://coveralls.io/repos/github/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/badge.svg?branch=main)](https://coveralls.io/github/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser?branch=main)\n[![Code Style](https://badgen.net/badge/code%20style/ts-standard/blue?icon=typescript)](https://github.com/standard/ts-standard)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\n# Jsdoc Type Pratt Parser\n\nThis project is a parser for jsdoc types. It takes jsdoc type expressions like `Array<string>` and creates an abstract\nsyntax tree (AST) out of it. It is heavily inspired by the existing libraries [catharsis](https://github.com/hegemonic/catharsis) and [jsdoctypeparser](https://github.com/jsdoctypeparser/jsdoctypeparser), but does\nnot use [PEG.js](https://pegjs.org/), instead it is written as a pratt parser.\n\nYou can find some more information about pratt parsers here:\n* https://en.wikipedia.org/wiki/Operator-precedence_parser#Pratt_parsing\n* http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/\n* https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html\n\n## Table of Contents\n- [Live Demo](#live-demo)\n- [Getting Started](#getting-started)\n- [API Documentation](#api-documentation)\n- [Available Grammars](#available-grammars)\n- [Transforms](#transforms)\n- [Traverse](#traverse)\n- [Custom Parsers and Stringifiers](#custom-parsers-and-stringifiers)\n- [Tests Status](#tests-status)\n- [Performance](#performance)\n- [Development](#development)\n\n## Live Demo\n\nA simple live demo to test expressions can be found at: https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/\n\n## Getting started\n\n```\nnpm install jsdoc-type-pratt-parser\n```\n\n```js\nimport { parse } from 'jsdoc-type-pratt-parser'\n\nconst result = parse('SomeType<string>', 'typescript')\n```\n\n## API Documentation\n\nAn API documentation can be found [here](https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/).\nIt is incomplete, but a good starting point. Please create issues or PRs if you don't find what you expect.\n\n## Available Grammars\n\nThree different modes (grammars) are supported: `'jsdoc'`, `'closure'` and `'typescript'`\n\n## Transforms\n\nA common task to do on ASTs are transforms, for example a stringification. This library includes some transform and\nutilities to implement your own.\n\n[`stringify`](https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/index.html#stringify):\n\n```js\nimport { stringify } from 'jsdoc-type-pratt-parser'\n\nconst val = stringify({ type: 'JsdocTypeName', value: 'name'}) // -> 'name'\n```\n\nYou can customize the stringification by using [`stringifyRules`](https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/index.html#stringifyRules)\nand [`transform`](https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/index.html#transform):\n\n```js\nimport { stringifyRules, transform } from 'jsdoc-type-pratt-parser'\n\nconst rules = stringifyRules()\n\n// `result` is the current node and `transform` is a function to transform child nodes.\nrules.NAME = (result, transform) => 'something else'\n\nconst val = transform(rules, { type: 'JsdocTypeName', value: 'name'}) // -> 'something else'\n```\n\nYou can also build your own transform rules by implementing the [`TransformRules<TransformResultType>`](https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/index.html#TransformRules) interface or you\ncan build upon the [identity ruleset](https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/index.html#identityTransformRules) like this:\n\n```js\nimport { identityTransformRules, transform } from 'jsdoc-type-pratt-parser'\n\nconst myRules = identityTransformRules()\nmyRules.NAME = () => ({ type: 'JsdocTypeName', value: 'funky' })\n\nconst val = transform(myRules, result)\n```\n\nThis library also supports compatibility modes for catharsis and jsdoctypeparser. The provided transform functions attempt to\n transform the output to the expected output of the target library. This will not always be the same as some types are\n parsed differently. These modes are thought to make transition easier, but it is advised to use the native output as\n this will be more uniform and will contain more information.\n\n[Catharsis compat mode](https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/index.html#catharsisTransform):\n\n```js\nimport { parse, catharsisTransform } from 'jsdoc-type-pratt-parser'\n\nconst result = catharsisTransform(parse('myType.<string>', 'closure'))\n```\n\n[Jsdoctypeparser compat mode](https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/index.html#jtpTransform):\n\n```js\nimport { parse, jtpTransform } from 'jsdoc-type-pratt-parser'\n\nconst result = jtpTransform(parse('myType.<string>', 'closure'))\n```\n\n## Traverse\n\nYou can traverse an AST with the [`traverse`](https://jsdoc-type-pratt-parser.github.io/jsdoc-type-pratt-parser/docs/index.html#traverse) function:\n\n```js\nimport { traverse } from 'jsdoc-type-pratt-parser'\n\n// property is the name of the property on parent that contains node\nfunction onEnter(node, parent, property) {\n  console.log(node.type)\n}\n\n// an onEnter and/or an onLeave function can be supplied\ntraverse({ type: 'JsdocTypeName', value: 'name'}, onEnter, console.log)\n```\n\n## Custom Parsers and Stringifiers\n\nFor TypeScript's computed property and methods, access to JavaScript\n(or TypeScript) parsing and stringification is required (beyond the\ntypes supported in `jsdoc-type-pratt-parser`). You can provide these\nby supplying the following optional arguments:\n\n```ts\nimport { parse as espree } from 'espree'\nimport { generate } from '@es-joy/escodegen'\n\nconst parsed = parse(\n  input,\n  mode,\n  { computedPropertyParser: espree }\n)\n\nconst stringified = stringify(\n  result,\n  generate\n)\n```\n\n## Tests Status\n\nThis parser runs most tests of [catharsis](https://github.com/hegemonic/catharsis) and\n[jsdoctypeparser](https://github.com/jsdoctypeparser/jsdoctypeparser). It compares the results of the different parsing libraries. If you\nwant to find out where the output differs, look in the tests for the comments `// This seems to be an error of ...` or\nthe `differ` keyword which indicates that differing results are produced.\n\n## Performance\n\nA simple [performance comparison](benchmark/benchmark.js) using [Benchmark.js](https://benchmarkjs.com/) produced the following results:\n```\nTesting expression: Name\ncatharsis x 37,816 ops/sec ±1.22% (1086 runs sampled)\njsdoc-type-pratt-parser x 602,617 ops/sec ±0.16% (1090 runs sampled)\njsdoctypeparser x 53,256 ops/sec ±0.73% (1081 runs sampled)\nThe fastest was jsdoc-type-pratt-parser\n\nTesting expression: Array<number>\ncatharsis x 10,124 ops/sec ±0.56% (1084 runs sampled)\njsdoc-type-pratt-parser x 228,660 ops/sec ±0.40% (1084 runs sampled)\njsdoctypeparser x 42,365 ops/sec ±0.60% (1070 runs sampled)\nThe fastest was jsdoc-type-pratt-parser\n\nTesting expression: { keyA: Type<A | \"string val\" >, keyB: function(string, B): A }\ncatharsis x 1,138 ops/sec ±0.66% (1087 runs sampled)\njsdoc-type-pratt-parser x 46,535 ops/sec ±0.47% (1090 runs sampled)\njsdoctypeparser x 18,291 ops/sec ±0.71% (1084 runs sampled)\nThe fastest was jsdoc-type-pratt-parser\n```\n\nThe benchmark test uses catharsis without cache.\n\n## Development\n\nIf you want to contribute see the [Development Guide](DEVELOPMENT.md) to get some pointers. Feel free to create issues if\nthere is information missing.\n\n## cjser\n\nThis package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.\nOriginal repository: https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser\n","readmeFilename":"README.md","_rev":"1-aa362d0cb8b4cb402e185443853bb459"}