JSPM

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

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.

Install

Install with npm:

npm i extract-comments --save-dev

Run tests

Run

npm test

API

extract

Extract code comments from the given string.

  • string {String}
  • returns {Object}: Object of code comments.

Example:

var extract = require('extract-comments');
extract('// this is a code comment');

.fromFiles

Extract code comments from a file or glob of files:

  • patterns {String}: Glob patterns to used.
  • options {Object}: Options to pass to globby, or map-files.
  • returns {Object}: Object of code comments.

Example:

var extract = require('extract-comments');
extract.fromFiles(['lib/*.js']);

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 24, 2014.