base-extract-comments
v0.1.2
Published
Base (github @node-base) application plugin for extracting code comments using `acorn-extract-comments`.
Downloads
9
Readme
base-extract-comments
Base (github @node-base) application plugin for extracting code comments using
acorn-extract-comments
.
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 withapp.options
and passed to acorn-extract-commentsreturns
{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 todone
callback. Notice that.extractComments
have sync and async mode, so if you do not passdone
callback it will throw or return an Array. You also can passinput
to the constructor of your app to thethis.cache
object such as{ cache: { input: 'some str' } }
Params
input
{String|Object|Function}: input string,options
ordone
callbackoptions
{Object|Function}: merged withapp.options
and passed to acorn-extract-comments ordone
callbackdone
{Function}: callback function (optional)returns
{Array}: an Array of comment objects ordone(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
- acorn-extract-comments: Extract JavaScript code comments from a string, using
acorn
. Optionally returns the… more | homepage - base-data: adds a
data
method to base-methods. | homepage - base-plugins-enhanced: Error handling and extras for
.use
and.run
methods of your Base… more | homepage - base-plugins: Upgrade's plugin support in base applications to allow plugins to be called… more | homepage
- base: base is the foundation for creating modular, unit testable and highly pluggable… more | homepage
- extract-comments: Uses esprima to extract line and block comments from a string of… more | homepage
- postcore: Processor engine for Post* family like PostCSS, PostHTML and PostJSON. | homepage
- use-ware: Adds sync plugin support to your application. Kinda fork of [use… more | homepage
- use: Easily add plugin support to your node.js application. | homepage
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.