{"_id":"jsdoc-type-pratt-parser@9.2.2","bugs":{"url":"https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues"},"dist":{"shasum":"8ba0d523a618bbd9752d15ed4b73608bd4672861","tarball":"http://registry-npm.ywwl.com/jsdoc-type-pratt-parser/download/jsdoc-type-pratt-parser-9.2.2.tgz","fileCount":5,"integrity":"sha512-eFY7Rlscvv/BpY6UsVsjKwMhu1tJO/F4U/vC9g3yeRy/JqszuO1UP6Vdq+85G+3FP6fEw/sWR8a5ftPFY86csw==","signatures":[{"sig":"MEQCIAm8ine9GVlrpIVo4qPaWVlOkqU44plg0Ie6YS5I55tUAiBju13fReCSg9lcuFGee86eEueRPHqL7Qr/xwXSR7enHA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBApJD9fSCBhfHMHW704vBGnAnNghhjRaMfp3g8lLOFeAiEA2t1VtCcdFjRzd1WdAeOllOjTKHoIYAkwlaGkcIvgcV0="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/jsdoc-type-pratt-parser@9.2.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":140473,"size":28194,"noattachment":false,"key":"/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-9.2.2.tgz"},"name":"jsdoc-type-pratt-parser","type":"module","types":"./dist/index.d.mts","author":{"url":"https://github.com/simonseyock","name":"Simon Seyock"},"engines":{"node":"^22.22.2 || >=24.15.0"},"exports":{".":"./dist/index.mjs","./package.json":"./package.json"},"gitHead":"07c0a5fb4f3a7318f423a4ccca255e49dc814035","license":"MIT","release":{"plugins":["@semantic-release/commit-analyzer","@semantic-release/github","@semantic-release/npm","@semantic-release/release-notes-generator","@semantic-release/changelog","@semantic-release/git"],"branches":["main",{"name":"dev","prerelease":true}]},"scripts":{"tsc":"tsc --noEmit","attw":"attw --pack . --profile esm-only","lint":"eslint .","test":"npm run tsc && npm run lint && npm run test:spec","build":"tsdown && npm run attw","apidoc":"typedoc --options typedoc.json","tsc:ts7":"npx -y -p typescript@^7 -c \"tsc\"","upgrade":"npm-upgrade","benchmark":"npm run build && node benchmark/benchmark.js","test:spec":"mocha","preversion":"npm test","test:coverage":"c8 --all npm run test:spec","prepublishOnly":"npm run build","test:coveralls":"c8 report --reporter=lcov && coveralls","semantic-release":"semantic-release"},"version":"9.2.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:9caea76a-7266-431d-ac31-f672e347b36a"}},"homepage":"https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser","keywords":["jsdoc","pratt","parser"],"repository":{"url":"git+https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser.git","type":"git"},"_npmVersion":"11.19.1","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)]","directories":{"test":"test"},"maintainers":[{"name":"simonseyock","email":"simonseyock@googlemail.com"},{"name":"simonseyock2","email":"simonseyock+jtpp@gmail.com"},{"name":"brettz9","email":"brettz9@yahoo.com"}],"ts-standard":{"ignore":["/submodules/","/build/","/pages/"]},"_nodeVersion":"24.20.0","contributors":[{"name":"Brett Zamir"}],"dependencies":{"@types/node":"^26.4.0","@types/estree":"^1.0.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","chai":"^6.2.2","mocha":"^12.0.0","sinon":"^22.1.0","eslint":"^9.39.4","espree":"^11.2.0","tsdown":"^0.22.14","ts-node":"^10.9.2","typedoc":"^0.28.20","benchmark":"^2.1.4","catharsis":"^0.11.0","coveralls":"^3.1.1","sinon-chai":"^4.0.1","typescript":"^6.0.3","@types/chai":"^5.2.3","npm-upgrade":"^3.3.0","@types/mocha":"^10.0.10","@types/sinon":"^22.0.0","patch-package":"^8.0.1","eslint-plugin-n":"^18.3.0","jsdoctypeparser":"^9.0.0","semantic-release":"^25.0.9","@es-joy/escodegen":"^4.2.0","@types/sinon-chai":"^4.0.0","eslint-config-love":"155.0.0","eslint-plugin-import":"^2.32.0","@arethetypeswrong/cli":"^0.18.5","@semantic-release/git":"^11.0.1","eslint-plugin-promise":"^7.3.0","@semantic-release/changelog":"^7.0.0","typedoc-plugin-merge-modules":"^7.0.0","@typescript-eslint/eslint-plugin":"^8.42.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jsdoc-type-pratt-parser_9.2.2_1789614411357_0.13373504944103787"},"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","publish_time":1789614411449,"_cnpm_publish_time":1789614411449,"dist-tags":{"alpha":"1.0.0-alpha.24","dev":"6.2.0-dev.2","latest":"9.5.0"}}