|
|
hace 3 años | |
|---|---|---|
| .. | ||
| lib | hace 3 años | |
| node_modules | hace 3 años | |
| LICENSE | hace 3 años | |
| README.md | hace 3 años | |
| index.js | hace 3 años | |
| package.json | hace 3 años | |
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).
Install with npm:
$ npm i extract-comments --save
var extract = require('extract-comments');
// pass a string of javascript, CSS, LESS etc
extract(string);
Example
var str = '/**\n * this is\n *\n * a comment\n*/\n\n\nvar foo = "bar";\n';
var comments = extract(str);
console.log(comments);
[{
type: 'block',
raw: '/**\n * this is\n *\n * a comment\n*/',
value: 'this is\na comment',
lines: [ 'this is', 'a comment' ],
loc: { start: { line: 1, pos: 0 }, end: { line: 5, pos: 33 } },
code:
{ line: 7,
loc: { start: { line: 7, pos: 36 }, end: { line: 7, pos: 52 } },
value: 'var foo = "bar";' }
Extract comments from the given string.
Params
string {String}options {Object}: Pass first: true to return after the first comment is found.returns {String}Example
extract(str, 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
extract.block(str, 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
extract.line(str, 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}Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Install dev dependencies:
$ npm i -d && npm test
As of December 30, 2015:
Statements : 100% (133/133)
Branches : 100% (32/32)
Functions : 100% (19/19)
Lines : 100% (132/132)
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 valueJon Schlinkert
Copyright © 2014-2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb on December 30, 2015.