JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 58535
  • Score
    100M100P100Q147626F

Extract code comments from string or from a glob of files.

Package Exports

  • extract-comments

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (extract-comments) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

extract-comments NPM version

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

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');

// pass a callback to process each comment
// directly after it's parsed
var context = require('code-context');
extract(str, function(comment) {
  comment.context = context(comment.after);
  return comment;
});

.fromFiles

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');

// we'll just pick an arbitrary comment:
comments['122'];

{ 'fixtures/assemble.js':
   // the line number
   { '122':
        // the starting line number (same as object key)
      { begin: 122,
        // the actual comment
        comment: 'Initialize default configuration.\n\n@api private\n',
        // the first non-whitespace line after the comment ends
        after: 'Assemble.prototype.defaultConfig = function (opts) {',
        // ending line number
        end: 126,
        // used when this object is merged with "code context", see below
        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.