Gathering detailed insights and metrics for extract-comment
Gathering detailed insights and metrics for extract-comment
Gathering detailed insights and metrics for extract-comment
Gathering detailed insights and metrics for extract-comment
babel-extract-comments
Uses babel (babylon) to extract JavaScript code comments from a JavaScript string or file.
esprima-extract-comments
Extract code comments from string or from a glob of files using esprima.
extract-comments
Extract code comments from a string.
jest-docblock
`jest-docblock` is a package that can extract and parse a specially-formatted comment called a "docblock" at the top of a file.
Extract JavaScript code comments from a string or glob of files.
npm install extract-comment
Typescript
Module System
Min. Node Version
Node Version
NPM Version
70.4
Supply Chain
99.3
Quality
74.6
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
3,639
Last Day
1
Last Week
2
Last Month
9
Last Year
174
MIT License
50 Stars
106 Commits
10 Forks
5 Watchers
1 Branches
3 Contributors
Updated on Jul 01, 2025
Minified
Minified + Gzipped
Latest Version
1.1.1
Package Id
extract-comment@1.1.1
Unpacked Size
19.25 kB
Size
5.89 kB
File Count
9
NPM Version
6.2.0
Node Version
9.11.2
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
2
Compared to previous week
Last Month
-30.8%
9
Compared to previous month
Last Year
-4.9%
174
Compared to previous year
2
Uses esprima to extract line and block comments from a string of JavaScript. Also optionally parses code context (the next line of code after a comment).
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
1$ npm install --save extract-comment
1var extract = require("extract-comment"); 2 3// pass a string of JavaScript 4extract(string);
Example
1var str = '/**\n * this is\n *\n * a comment\n*/\n\n\nvar foo = "bar";\n'; 2var comments = extract(str); 3console.log(comments); 4 5[{ 6 type: 'block', 7 raw: '/**\n * this is\n *\n * a comment\n*/', 8 value: 'this is\na comment', 9 loc: { start: { line: 1, column: 0 }, end: { line: 5, column: 33 } }, 10 code: 11 { line: 7, 12 loc: { start: { line: 7, column: 36 }, end: { line: 7, column: 52 } }, 13 value: 'var foo = "bar";' }
By default, esprima is used for extracting comments. This can easily be changed by passing a function to options.extractor
.
The easy way
Use a published module, such as:
Example:
1extract(str, { extractor: require("babel-extract-comments") });
If you create a compatible extractor, feel free to do pr or create an issue to add it to the readme!
Roll your own
1extract(str, {
2 extractor: function(str) {
3 // must return an array of tokens with:
4 // - type: 'Block', 'CommentBlock', 'Line' or 'CommentLine'
5 // - value: the comment inner string
6 // - loc: with `start` and `end` line and column
7 // example:
8 return [
9 {
10 type: 'Block',
11 {start: { line: 1, column: 0 },
12 end: { line: 5, column: 33 }},
13 value: ' this is a comment string '
14 }
15 ];
16 }
17});
Extract comments from the given string
.
Params
string
{String}options
{Object}: Pass first: true
to return after the first comment is found.tranformFn
{Function}: (optional) Tranform function to modify each commentreturns
{Array}: Returns an array of comment objectsExample
1const extract = require("extract-comment"); 2console.log(extract(string, options));
Extract block comments from the given string
.
Params
string
{String}options
{Object}: Pass first: true
to return after the first comment is found.returns
{String}Example
1console.log(extract.block(string, options));
Extract line comments from the given string
.
Params
string
{String}options
{Object}: Pass first: true
to return after the first comment is found.returns
{String}Example
1console.log(extract.line(string, options));
Extract the first comment from the given string
.
Params
string
{String}options
{Object}: Pass first: true
to return after the first comment is found.returns
{String}Example
1console.log(extract.first(string, options));
v0.10.0
loc.start.pos
and loc.end.pos
properties have been renamed to loc.start.column
and loc.end.column
.v0.9.0
lines
property was removed from Block
comments, since this can easily be done by splitting value
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running 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:
1$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
Commits | Contributor |
---|---|
93 | jonschlinkert |
3 | cazzer |
1 | architectcodes |
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on February 12, 2018.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More