{"id":15365573,"url":"https://github.com/tunnckocore/acorn-extract-comments","last_synced_at":"2026-08-16T12:30:16.378Z","repository":{"id":32692476,"uuid":"36281740","full_name":"tunnckoCore/acorn-extract-comments","owner":"tunnckoCore","description":"Extract JavaScript code (block, jsdoc style) comments from a string, using `acorn`. Optionally returns the AST and first line of code after comment - useful for parsing code context and api docs.","archived":false,"fork":false,"pushed_at":"2017-07-20T21:02:43.000Z","size":17,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-08-14T12:52:08.029Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/tunnckoCore.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"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":"2015-05-26T08:14:50.000Z","updated_at":"2025-10-08T00:55:01.000Z","dependencies_parsed_at":"2022-09-11T16:33:24.498Z","dependency_job_id":null,"html_url":"https://github.com/tunnckoCore/acorn-extract-comments","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tunnckoCore/acorn-extract-comments","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Facorn-extract-comments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Facorn-extract-comments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Facorn-extract-comments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Facorn-extract-comments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tunnckoCore","download_url":"https://codeload.github.com/tunnckoCore/acorn-extract-comments/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Facorn-extract-comments/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":36714792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-08-06T04:43:03.162Z","status":"online","status_checked_at":"2026-08-16T02:00:06.462Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-01T13:15:08.970Z","updated_at":"2026-08-16T12:30:16.123Z","avatar_url":"https://github.com/tunnckoCore.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [acorn-extract-comments][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] \n\n\u003e Extract JavaScript code comments from a string, using `acorn`.\n\n[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url]\n\n\n## Install\n```\nnpm i acorn-extract-comments --save\n```\n\n\n## Usage\n\u003e For more use-cases see the [tests](./test.js)\n\n```js\nconst extract = require('acorn-extract-comments')\n```\n\n\n### [acornExtractComments](index.js#L42)\n\u003e Extract all code comments, including block/line and also these that are marked as \"ignored\" like (`//!` and `/*!`)\n\n**Params**\n\n* `\u003cinput\u003e` **{String}**: string from which to get comments    \n* `[opts]` **{Object}**: optional options, passed to `acorn`  \n  - `ast` **{Boolean}**: if `true` the ast is added to the resulting array\n  - `line` **{Boolean}**: if `false` get only block comments, default `true`\n  - `block` **{Boolean}**: if `false` get line comments, default `true`\n  - `preserve` **{Boolean|Function}**: if `true` will get only comments that are **not** ignored\n  - `locations` **{Boolean}**: if `true` result will include `acorn` location object\n  - `ecmaVersion` **{Number}**: defaults to `6`, acorn parsing version\n* `returns` **{Array}**: can have `.ast` property if `opts.ast: true`  \n\n**Example**\n\n```js\nconst fs = require('fs')\nconst extract = require('acorn-extract-comments')\n\nconst str = fs.readFileSync('./index.js', 'utf8')\nconst comments = extract(str, {})\n// =\u003e ['array', 'of', 'all', 'code', 'comments']\n```\n\n### [.line](index.js#L70)\n\u003e Extract only line comments.\n\n**Params**\n\n* `\u003cinput\u003e` **{String}**: string from which to get comments    \n* `[opts]` **{Object}**: optional options, passed to `acorn`    \n* `returns` **{Array}**: can have `.ast` property if `opts.ast: true`  \n\n**Example**\n\n```js\nconst comments = extract(str, {block: false})\n// =\u003e ['array', 'of', 'line', 'comments']\n```\n\nor through method\n\n```js\nconst comments = extract.line(str)\n// =\u003e ['all', 'line', 'comments']\n```\n\n### [.block](index.js#L98)\n\u003e Extract only block comments.\n\n**Params**\n\n* `\u003cinput\u003e` **{String}**: string from which to get comments    \n* `[opts]` **{Object}**: optional options, passed to `acorn`    \n* `returns` **{Array}**: can have `.ast` property if `opts.ast: true`  \n\n**Examples**\n\n```js\nconst comments = extract(str, {line: false})\n// =\u003e ['array', 'of', 'block', 'comments']\n```\n\nor through method\n\n```js\nconst comments = extract.block(str)\n// =\u003e ['array', 'of', 'block', 'comments']\n```\n\n\n## Contributing\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/tunnckoCore/acorn-extract-comments/issues/new).  \nBut before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines.\n\n\n## [Charlike Make Reagent](http://j.mp/1stW47C) [![new message to charlike][new-message-img]][new-message-url] [![freenode #charlike][freenode-img]][freenode-url]\n\n[![tunnckocore.tk][author-www-img]][author-www-url] [![keybase tunnckocore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url]\n\n\n[npmjs-url]: https://www.npmjs.com/package/acorn-extract-comments\n[npmjs-img]: https://img.shields.io/npm/v/acorn-extract-comments.svg?label=acorn-extract-comments\n\n[license-url]: https://github.com/tunnckoCore/acorn-extract-comments/blob/master/LICENSE\n[license-img]: https://img.shields.io/badge/license-MIT-blue.svg\n\n\n[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/acorn-extract-comments\n[codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/acorn-extract-comments.svg\n\n[travis-url]: https://travis-ci.org/tunnckoCore/acorn-extract-comments\n[travis-img]: https://img.shields.io/travis/tunnckoCore/acorn-extract-comments.svg\n\n[coveralls-url]: https://coveralls.io/r/tunnckoCore/acorn-extract-comments\n[coveralls-img]: https://img.shields.io/coveralls/tunnckoCore/acorn-extract-comments.svg\n\n[david-url]: https://david-dm.org/tunnckoCore/acorn-extract-comments\n[david-img]: https://img.shields.io/david/tunnckoCore/acorn-extract-comments.svg\n\n[standard-url]: https://github.com/feross/standard\n[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n\n\n[author-www-url]: http://www.tunnckocore.tk\n[author-www-img]: https://img.shields.io/badge/www-tunnckocore.tk-fe7d37.svg\n\n[keybase-url]: https://keybase.io/tunnckocore\n[keybase-img]: https://img.shields.io/badge/keybase-tunnckocore-8a7967.svg\n\n[author-npm-url]: https://www.npmjs.com/~tunnckocore\n[author-npm-img]: https://img.shields.io/badge/npm-~tunnckocore-cb3837.svg\n\n[author-twitter-url]: https://twitter.com/tunnckoCore\n[author-twitter-img]: https://img.shields.io/badge/twitter-@tunnckoCore-55acee.svg\n\n[author-github-url]: https://github.com/tunnckoCore\n[author-github-img]: https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg\n\n[freenode-url]: http://webchat.freenode.net/?channels=charlike\n[freenode-img]: https://img.shields.io/badge/freenode-%23charlike-5654a4.svg\n\n[new-message-url]: https://github.com/tunnckoCore/ama\n[new-message-img]: https://img.shields.io/badge/ask%20me-anything-green.svg","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftunnckocore%2Facorn-extract-comments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftunnckocore%2Facorn-extract-comments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftunnckocore%2Facorn-extract-comments/lists"}