{"name":"comment-parser","version":"1.4.2","keywords":["jsdoc","comments","parser"],"author":{"url":"https://github.com/syavorsky","name":"Sergiy Yavorsky","email":"sergiy@yavorsky.me"},"license":"MIT","_id":"comment-parser@1.4.2","maintainers":[{"name":"yavorskiys","email":"sergiy@yavorsky.me"}],"contributors":[{"url":"https://github.com/alexgrozav","name":"Alex Grozav"},{"url":"https://github.com/zxqfox","name":"Alexej Yaroshevich"},{"url":"https://github.com/blutorange","name":"Andre Wachsmuth"},{"url":"https://github.com/brettz9","name":"Brett Zamir"},{"url":"https://github.com/doberkofler","name":"Dieter Oberkofler"},{"url":"https://github.com/zxcabs","name":"Evgeny Reznichenko"},{"url":"https://github.com/jhm-ciberman","name":"Javier \"Ciberma\" Mora"},{"url":"https://github.com/jaydenseric","name":"Jayden Seric"},{"url":"https://github.com/ljharb","name":"Jordan Harband"},{"url":"https://github.com/tengattack","name":"tengattack"}],"homepage":"https://github.com/syavorsky/comment-parser","bugs":{"url":"https://github.com/syavorsky/comment-parser/issues"},"dist":{"shasum":"55e471b14d1fbc5577de180c7ec80323d0a31239","tarball":"http://registry-npm.ywwl.com/comment-parser/download/comment-parser-1.4.2.tgz","fileCount":93,"integrity":"sha512-bm63OZFy8PkeZgRiLqJvtZHGLHaaws2WVZaTtSgqk3Cna47QhciTRSb0SSmYS1AzstC0zw1+9RncmhmWIaWwqA==","signatures":[{"sig":"MEYCIQCxIB+GglPngSVUgdmYrhXg6KcACf1e8wm4Eyg9B5aeTAIhALJBZmmSsITziPu3NYeTYst/uNfQLrVr2hkpwbUKBe4d","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":241638,"size":40273,"noattachment":false,"key":"/comment-parser/-/comment-parser-1.4.2.tgz"},"main":"lib/index.cjs","type":"module","types":"lib/index.d.ts","engines":{"node":">= 12.0.0"},"exports":{".":{"import":"./es6/index.js","require":"./lib/index.cjs"},"./util":{"import":"./es6/util.js","require":"./lib/util.cjs"},"./parser/*":{"import":"./es6/parser/*.js","require":"./lib/parser/*.cjs"},"./primitives":{"import":"./es6/primitives.js","require":"./lib/primitives.cjs"},"./transforms/*":{"import":"./es6/transforms/*.js","require":"./lib/transforms/*.cjs"},"./stringifier/*":{"import":"./es6/stringifier/*.js","require":"./lib/stringifier/*.cjs"}},"gitHead":"81597e9c6a724a8036ba4be5044193f06751ec77","scripts":{"test":"prettier --check src tests && jest --verbose","build":"rimraf lib es6 browser; tsc -p tsconfig.json && tsc -p tsconfig.node.json && rollup -o browser/index.js -f iife --context window -n CommentParser es6/index.js && convert-extension cjs lib/","format":"prettier --write src tests","pretest":"rimraf coverage; npm run build","preversion":"npm run build"},"_npmUser":{"name":"yavorskiys","email":"sergiy@yavorsky.me"},"repository":{"url":"git+ssh://git@github.com/yavorskiy/comment-parser.git","type":"git"},"_npmVersion":"10.2.4","description":"Generic JSDoc-like comment parser","directories":{"test":"tests"},"_nodeVersion":"20.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^30.1.3","rimraf":"^6.0.1","rollup":"^4.52.0","ts-jest":"^29.4.4","prettier":"3.6.2","typescript":"^5.9.2","@types/jest":"^30.0.0","@changesets/cli":"^2.29.8","convert-extension":"^0.3.0"},"_npmOperationalInternal":{"tmp":"tmp/comment-parser_1.4.2_1768601462127_0.2877981581582618","host":"s3://npm-registry-packages-npm-production"},"readme":"# comment-parser\n\n`comment-parser` is a library helping to handle Generic JSDoc-style comments. It is\n\n- **language-agnostic** – no semantics enforced. You decide what tags are and what they mean. And it can be used with any language supporting `/** */` source comments.\n- **no dependencies** – it is compact and environment-agnostic, can be run on both the server and browser sides\n- **highly customizable** – with a little code you can deeply customize how comments are parsed\n- **bidirectional** - you can write comment blocks back to the source after updating or formatting\n- **strictly typed** - comes with generated `d.ts` data definitions since written in TypeScript\n\n```sh\nnpm install comment-parser\n```\n\n> 💡 Check out the [Playground](https://syavorsky.github.io/comment-parser)\n\n> 💡 Previous version lives in [0.x](https://github.com/syavorsky/comment-parser/tree/0.x) branch\n\nLib mainly provides two pieces [Parser](#Parser) and [Stringifier](#Stringifier).\n\n## Parser\n\nLet's go over string parsing:\n\n```js\nconst { parse } = require('comment-parser/lib')\n\nconst source = `\n/**\n * Description may go\n * over few lines followed by @tags\n * @param {string} name the name parameter\n * @param {any} value the value of any type\n */`\n\nconst parsed = parse(source)\n```\n\nLib source code is written in TypeScript and all data shapes are conveniently available for your IDE of choice. All types described below can be found in [primitives.ts](src/primitives.ts)\n\nThe input source is first parsed into lines, then lines split into tokens, and finally, tokens are processed into blocks of tags\n\n### Block\n\n```js\n/**\n * Description may go\n * over multiple lines followed by @tags\n * @param {string} name the name parameter\n * @param {any} value the value parameter\n */\n```\n\n### Description\n\n```js\n/**\n * Description may go\n * over multiple lines followed by @tags\n```\n\n### Tags\n\n```js\n * @param {string} name the name parameter\n```\n\n```js\n * @param {any} value the value parameter\n */\n```\n\n### Tokens\n\n```\n|line|start|delimiter|postDelimiter|tag   |postTag|name |postName|type    |postType|description                     |end|\n|----|-----|---------|-------------|------|-------|-----|--------|--------|--------|--------------------------------|---|\n|   0|{2}  |/**      |             |      |       |     |        |        |        |                                |   |\n|   1|{3}  |*        |{1}          |      |       |     |        |        |        |Description may go              |   |\n|   2|{3}  |*        |{1}          |      |       |     |        |        |        |over few lines followed by @tags|   |\n|   3|{3}  |*        |{1}          |@param|{1}    |name |{1}     |{string}|{1}     |the name parameter              |   |\n|   4|{3}  |*        |{1}          |@param|{1}    |value|{1}     |{any}   |{1}     |the value of any type           |   |\n|   5|{3}  |         |             |      |       |     |        |        |        |                                |*/ |\n```\n\n### Result\n\nThe result is an array of Block objects, see the full output on the [playground](https://syavorsky.github.io/comment-parser)\n\n```js\n[{\n  // uppper text of the comment, overall block description\n  description: 'Description may go over multiple lines followed by @tags',\n  // list of block tags: @param, @param\n  tags: [{\n    // tokens.tag without \"@\"\n    tag: 'param',\n    // unwrapped tokens.name\n    name: 'name',\n    // unwrapped tokens.type\n    type: 'string',\n    // true, if tokens.name is [optional]\n    optional: false,\n    // default value if optional [name=default] has one\n    default: undefined,\n    // tokens.description assembled from a siongle or multiple lines\n    description: 'the name parameter',\n    // problems occured while parsing this tag section, subset of ../problems array\n    problems: [],\n    // source lines processed for extracting this tag, \"slice\" of the ../source item reference\n    source: [ ... ],\n  }, ... ],\n  // source is an array of `Line` items having the source\n  // line number and `Tokens` that can be assembled back into\n  // the line string preserving original formatting\n  source: [{\n    // source line number\n    number: 1,\n    // source line string\n    source: \"/**\",\n    // source line tokens\n    tokens: {\n      // indentation\n      start: \"\",\n      // delimiter, either '/**', '*/', '*', or ''. Mid lines may have no delimiters\n      delimiter: \"/**\",\n      // space between delimiter and tag\n      postDelimiter: \"\",\n      // tag starting with \"@\"\n      tag: \"\",\n      // space between tag and type\n      postTag: \"\",\n      // name with no whitespaces or \"multiple words\" wrapped into quotes. May occure in [name] and [name=default] forms\n      name: \"\",\n      // space between name and type\n      postName: \"\",\n      // type is has to be {wrapped} into curlies otherwise will be omitted\n      type: \"\",\n      // space between type and description\n      postType: \"\",\n      // description is basicaly rest of the line\n      description: \"\",\n      // closing */ marker if present\n      end: \"\"\n    }\n  }, ... ],\n  // problems occured while parsing the block\n  problems: [],\n}];\n```\n\nWhile `.source[].tokens` are not providing readable annotation information, they are essential for tracing data origins and assembling string blocks with `stringify`\n\n### options\n\n```ts\ninterface Options {\n  // start count for source line numbers\n  startLine: number;\n  // escaping chars sequence marking wrapped content literal for the parser\n  fence: string;\n  // block and comment description compaction strategy\n  spacing: 'compact' | 'preserve';\n  // tokenizer functions extracting name, type, and description out of tag, see Tokenizer\n  tokenizers: Tokenizer[];\n}\n```\n\nexamples\n- [default config](https://syavorsky.github.io/comment-parser/#parse-defaults)\n- [line numbers control](https://syavorsky.github.io/comment-parser/#parse-line-numbering)\n- [description spacing](https://syavorsky.github.io/comment-parser/#parse-spacing)\n- [escaping](https://syavorsky.github.io/comment-parser/#parse-escaping)\n- [explore the origin source](https://syavorsky.github.io/comment-parser/#parse-source-exploration)\n\n[suggest more examples](https://github.com/syavorsky/comment-parser/issues/new?title=example+suggestion%3A+...&labels=example,parser)\n\n## Stringifier\n\nThe stringifier is an important piece used by other tools updating the source code. It goes over `Block.source[].tokens` items and assembles them back to the string. It might be used with various transforms applied before stringifying.\n\n```js\nconst { parse, stringify, transforms: {flow, align, indent} } = require('comment-parser');\n\nconst source = `\n  /**\n   * Description may go\n   * over multiple lines followed by @tags\n   *\n* @my-tag {my.type} my-name description line 1\n      description line 2\n    * description line 3\n   */`;\n\nconst parsed = parse(source);\nconst transform = flow(align(), indent(0))\nconsole.log(stringify(transform(parsed[0])));\n```\n\n### Result\n\n```js\n/**\n * Description may go\n * over multiple lines followed by @tags\n *\n * @my-tag {my.type} my-name description line 1\n                             description line 2\n *                           description line 3\n */\n```\n\nexamples\n- [format comments](https://syavorsky.github.io/comment-parser/#stringify-formatting)\n\n[suggest more examples](https://github.com/syavorsky/comment-parser/issues/new?title=example+suggestion%3A+...&labels=example,stringifier)\n\n## Migrating from 0.x version\n\nCode of pre-1.0 version is forked into [0.x](https://github.com/syavorsky/comment-parser/tree/0.x) and will phase out eventually. Please file the issue if you find some previously existing functionality can't be achieved with 1.x API. Check out [migration notes](migrate-1.0.md).\n","publish_time":1768601462287,"_cnpm_publish_time":1768601462287,"dist-tags":{"latest":"1.4.11"}}