Extract code comments from string or from a glob of files.
Install
Install with npm:
npm i extract-comments --save-dev
Run tests
Run
npm test
API
Extract code comments from a glob of files:
patterns
{String}: Glob patterns to used.options
{Object}: Options to pass to [esprima] or [globby], or [map-files].returns
{Object}: Object of code comments.
Example:
var extract = require('extract-comments');
extract('lib/*.js');
Extract code comments from the given string
.
string
{String}options
{Object}: Options to pass to esprima.returns
{Object}: Object of code comments.
Example:
var extract = require('extract-comments');
extract.fromString('// this is a code comment');
You may also pass a custom rename
function on the options to change the key of each object returned. See map-files for more details and available options.
Example results
{ 'test/fixtures/assemble.js':
[ { type: 'Block',
value: '!\n * assemble <https://github.com/assemble/assemble>\n *\n * Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.\n * Licensed under the MIT license.\n ',
loc: { start: { line: 1, column: 0 }, end: { line: 6, column: 3 } } },
{ type: 'Line',
value: ' Module dependencies',
loc:
{ start: { line: 10, column: 0 },
end: { line: 10, column: 22 } } },
{ type: 'Line',
value: ' Local modules.',
loc:
{ start: { line: 39, column: 0 },
end: { line: 39, column: 17 } } },
{ type: 'Line',
value: ' Plugins and middleware',
loc:
{ start: { line: 44, column: 0 },
end: { line: 44, column: 25 } } },
{ type: 'Block',
value: '*\n * Set the current working directory for all paths.\n * Default is `process.cwd()`, this does not need to\n * be changed unless you require something different.\n *\n * ```js\n * assemble.cwd(\'bench\');\n * ```\n *\n * @param {String|Array} `args` File path or paths.\n * @return {String}\n * @api public\n ',
loc:
{ start: { line: 414, column: 0 },
end: { line: 426, column: 3 } } },
Or when extract.fromString()
is used:
{ type: 'Block',
value: '!\n * assemble <https://github.com/assemble/assemble>\n *\n * Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.\n * Licensed under the MIT license.\n ',
loc: { start: { line: 1, column: 0 }, end: { line: 6, column: 3 } } },
{ type: 'Line',
value: ' Module dependencies',
loc:
{ start: { line: 10, column: 0 },
end: { line: 10, column: 22 } } },
{ type: 'Line',
value: ' Local modules.',
loc:
{ start: { line: 39, column: 0 },
end: { line: 39, column: 17 } } },
{ type: 'Line',
value: ' Plugins and middleware',
loc:
{ start: { line: 44, column: 0 },
end: { line: 44, column: 25 } } }
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on September 20, 2014.