Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extract-comments

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extract-comments

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

  • 0.5.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
47K
decreased by-7.69%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 13 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc