{"id":15642046,"url":"https://github.com/jonschlinkert/parse-comments","last_synced_at":"2025-09-08T15:31:55.836Z","repository":{"id":19546217,"uuid":"22794576","full_name":"jonschlinkert/parse-comments","owner":"jonschlinkert","description":" Parse JavaScript code comments. Works with block and line comments, and should work with CSS, LESS, SASS, or any language with the same comment formats.","archived":false,"fork":false,"pushed_at":"2022-12-19T13:58:08.000Z","size":614,"stargazers_count":67,"open_issues_count":11,"forks_count":23,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-26T23:06:27.083Z","etag":null,"topics":["apidoc","babel","catharsis","code","comments","context","docs","doctrine","documentation","espree","esprima","javascript","jonschlinkert","jsdoc","markdown","nodejs","parse"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-09T20:32:46.000Z","updated_at":"2024-10-18T12:54:19.000Z","dependencies_parsed_at":"2023-01-13T20:26:38.537Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/parse-comments","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fparse-comments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fparse-comments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fparse-comments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fparse-comments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/parse-comments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232320251,"owners_count":18504974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apidoc","babel","catharsis","code","comments","context","docs","doctrine","documentation","espree","esprima","javascript","jonschlinkert","jsdoc","markdown","nodejs","parse"],"created_at":"2024-10-03T11:53:51.962Z","updated_at":"2025-01-03T10:09:53.836Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","readme":"# parse-comments [![NPM version](https://img.shields.io/npm/v/parse-comments.svg?style=flat)](https://www.npmjs.com/package/parse-comments) [![NPM monthly downloads](https://img.shields.io/npm/dm/parse-comments.svg?style=flat)](https://npmjs.org/package/parse-comments) [![NPM total downloads](https://img.shields.io/npm/dt/parse-comments.svg?style=flat)](https://npmjs.org/package/parse-comments) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/parse-comments.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/parse-comments)\n\n\u003e Parse code comments from JavaScript or any language that uses the same format.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save parse-comments\n```\n\n## Usage\n\n```js\nconst Comments = require('parse-comments');\nconst comments = new Comments();\nconst ast = comments.parse(str);\nconsole.log(ast);\n```\n\nParses a comment like this:\n\n```js\n/**\n * Create an instance of `CustomClass` with the given `options`.\n *\n * @param {String} options\n * @api public\n */\n\nclass CustomClass {\n  constructor(options) {\n    this.options = options;\n  }\n  set(type, fn) {\n    // do stuff\n  }\n}\n```\n\nInto an array of comment objects, like this:\n\n```js\n[\n  {\n    type: 'BlockComment',\n    value: '\\nCreate an instance of `CustomClass` with the given `options`.\\n\\n@param {String} options\\n@api public',\n    range: [0, 117],\n    loc: { start: { line: 1, column: 0 }, end: { line: 6, column: 3 } },\n    codeStart: 119,\n    raw:\n      '*\\n * Create an instance of `CustomClass` with the given `options`.\\n *\\n * @param {String} options\\n * @api public\\n ',\n    code: {\n      context: {\n        type: 'class',\n        ctor: 'CustomClass',\n        name: 'CustomClass',\n        extends: undefined,\n        string: 'new CustomClass()'\n      },\n      value: 'class CustomClass {',\n      range: [119, 138],\n      loc: { start: { line: 8, column: 0 }, end: { line: 8, column: 19 } }\n    },\n    description: 'Create an instance of `CustomClass` with the given `options`.',\n    footer: '',\n    examples: [],\n    tags: [\n      {\n        title: 'param',\n        name: 'options',\n        description: '',\n        type: { type: 'NameExpression', name: 'String' }\n      },\n      { title: 'api', name: 'public', description: '' }\n    ],\n    inlineTags: []\n  }\n]\n```\n\n## API\n\n### [Comments](index.js#L22)\n\nCreate an instance of `Comments` with the given `options`.\n\n**Params**\n\n* **{Object}**: options\n\n**Example**\n\n```js\nconst Comments = require('parse-comments');\nconst comments = new Comments();\n```\n\nRegister a parser function of the given `type`\n\n**Params**\n\n* `type` **{string|object}**\n* `fn` **{Function}**\n* `returns` **{Object}**\n\n**Params**\n\n* `fn` **{Function}**: plugin function\n* `returns` **{Object}**: Returns the comments instance for chaining.\n\n**Example**\n\n```js\n// plugin example\nfunction yourPlugin(options) {\n  return function(comments) {\n    // do stuff\n  };\n}\n// usage\ncomments.use(yourPlugin());\n```\n\n**Params**\n\n* `type` **{String}**: The `node.type` to call the handler on. You can override built-in middleware by registering a handler of the same name, or register a handler for rendering a new type.\n* `fn` **{Function}**: The handler function\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Example**\n\n```js\ncomments.set('param', function(node) {\n  // do stuff to node\n});\n```\n\n**Params**\n\n* `type` **{String|Object|Array}**: Handler name(s), or an object of middleware\n* `fn` **{Function}**: Handler function, if `type` is a string or array. Otherwise this argument is ignored.\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Example**\n\n```js\ncomments.before('param', function(node) {\n  // do stuff to node\n});\n\n// or\ncomments.before(['param', 'returns'], function(node) {\n  // do stuff to node\n});\n\n// or\ncomments.before({\n  param: function(node) {\n    // do stuff to node\n  },\n  returns: function(node) {\n    // do stuff to node\n  }\n});\n```\n\n**Params**\n\n* `type` **{String|Object|Array}**: Handler name(s), or an object of middleware\n* `fn` **{Function}**: Handler function, if `type` is a string or array. Otherwise this argument is ignored.\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Example**\n\n```js\ncomments.after('param', function(node) {\n  // do stuff to node\n});\n\n// or\ncomments.after(['param', 'returns'], function(node) {\n  // do stuff to node\n});\n\n// or\ncomments.after({\n  param: function(node) {\n    // do stuff to node\n  },\n  returns: function(node) {\n    // do stuff to node\n  }\n});\n```\n\n**Params**\n\n* `javascript` **{String}**: String of javascript\n* `options` **{Object}**\n* `returns` **{Object}**: Returns an object with `description` string, array of `examples`, array of `tags` (strings), and a `footer` if descriptions are defined both before and after tags.\n\n**Example**\n\n```js\nconst parser = new ParseComments();\nconst tokens = parser.tokenize([string]);\n```\n\n**Params**\n\n* `str` **{String}**: String of javascript\n* `options` **{Object}**\n* `returns` **{Array}**: Array of objects.\n\n**Example**\n\n```js\nconst parser = new ParseComments();\nconst comments = parser.parse(string);\n```\n\n**Params**\n\n* `str` **{String}**: JavaScript comment\n* `options` **{Object}**\n* `returns` **{Object}**: Parsed comment object\n\n**Example**\n\n```js\nlet parser = new ParseComments();\nlet comments = parser.parseComment(string);\n```\n\n```js\n\n**Params**\n\n* **{}**: {String}    \n* **{String}**: name    \n* **{String}**: name The name to use for foo ```    \n* **{Object}**: tok Takes a token from    \n* `returns` **{Object}**  \n\n```js\n\n**Params**\n\n* **{}**: {String}\n* **{String}**: name\n* **{String}**: name The name to use for foo ```\n* **{Object}**: tok\n* `returns` **{Object}**\n\n```js\n\n**Params**\n\n* **{}**: {String}    \n* **{}**: {...string}    \n* **{}**: {function(...a)}    \n* **{}**: {function(...a:b)}    \n* **{}**: {String|Array}    \n* **{}**: {(String|Array)}    \n* **{}**: {{foo: bar}}    \n* **{}**: {String[]}    \n* ``` **{Array\u003cString|Function|Array\u003e=}**    \n* **{String}**: value The    \n* `returns` **{Object}**  \n\n```js\n\n**Params**\n\n* **{}**: {String}\n* **{}**: {String|Array}\n* **{}**: {(String|Array)}\n* **{}**: {{foo: bar}} ```\n* **{string}**: str The string to parse\n* `returns` **{object}**\n\nReturns true if the given `comment` is valid. By default, comments\nare considered valid when they begin with `/**`, and do not contain\n`jslint`, `jshint`, `eshint`, or `eslint`. A custom `isValid` function may be\npassed on the constructor options.\n\n**Params**\n\n* `comment` **{Object}**\n* `options` **{Object}**\n* `returns` **{Boolean}**\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 35 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 4  | [doowb](https://github.com/doowb) |  \n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 24, 2018._","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fparse-comments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fparse-comments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fparse-comments/lists"}