Extract code comments from string or from a glob of files.
This goes well with code-context.
Install with npm
npm i extract-comments --save
API
Extract code comments from the given string
.
string
{String}returns
{Object}: Object of code comments.
var extract = require('extract-comments');
extract('// this is a code comment');
var context = require('code-context');
extract(str, function(comment) {
comment.context = context(comment.after);
return comment;
});
Extract code comments from a file or glob of files. You may also pass a custom rename
function on the options to change the key of each object returned.
patterns
{String}: Glob patterns to used.options
{Object}: Options to pass to [globby], or map-files.returns
{Object}: Object of code comments.
See map-files for more details and available options.
var extract = require('extract-comments');
extract.fromFiles(['lib/*.js']);
Usage example
var extract = require('extract-comments');
var comments = extract.fromFile('fixtures/assemble.js');
comments['122'];
{ 'fixtures/assemble.js':
{ '122':
{ begin: 122,
comment: 'Initialize default configuration.\n\n@api private\n',
after: 'Assemble.prototype.defaultConfig = function (opts) {',
end: 126,
type: 'comment' }
Run tests
Install dev dependencies:
npm i -d && npm test
Author
Jon Schlinkert
License
Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb on February 13, 2015.