base-extract-comments

0.1.2 • Public • Published

base-extract-comments npmjs.com The MIT License npm downloads

Base (github @node-base) application plugin for extracting code comments using acorn-extract-comments.

code climate standard code style travis build status coverage status dependency status

Install

npm i base-extract-comments --save

Usage

For more use-cases see the tests

const baseExtractComments = require('base-extract-comments')

baseExtractComments

Plugin that adds .extractComments method to your base application, that extracts JSDoc-style code comments using acorn-extract-comments lib.

Params

  • opts {Object}: merged with app.options and passed to acorn-extract-comments
  • returns {Function}: the actual plugin

Example

var extract = require('base-extract-comments')
var Base = require('base')
var app = new Base({ isApp: true })
 
app.use(extract({ foo: 'option' }))
console.log(app.extractComments) // => [Function: extractComments]

.extractComments

Extract code comments from input string and returns an array of comment objects or pass it to done callback. Notice that .extractComments have sync and async mode, so if you do not pass done callback it will throw or return an Array. You also can pass input to the constructor of your app to the this.cache object such as { cache: { input: 'some str' } }

Params

  • input {String|Object|Function}: input string, options or done callback
  • options {Object|Function}: merged with app.options and passed to acorn-extract-comments or done callback
  • done {Function}: callback function (optional)
  • returns {Array}: an Array of comment objects or done(null, comments)

Example

// sync mode
 
app.use(extract())
var comments = app.extractComments('some string')
// => array of comment objects
 
// or
 
var app = new Base({ cache: { input: 'foo bar baz' } })
app.use(extract())
var comments = app.extractComments()
// => array of comment objects
 
// or in async mode
 
app.use(extract())
app.extractComments('foo bar', function done (err, comments) {
  // => `comments` is array of comment objects
})

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

/base-extract-comments/

    Package Sidebar

    Install

    npm i base-extract-comments

    Weekly Downloads

    0

    Version

    0.1.2

    License

    MIT

    Last publish

    Collaborators

    • vanchoy
    • tunnckocore