plugins

Run a value through a plugin stack.

plugins

Run a value through a plugin stack.

Install with npm

$ npm i plugins --save

See the examples.

(Table of contents generated by verb)

See the examples.

A plugin can take any arguments and must return a function.

Plugins just return a value.

Example:

var plugins = new Plugins();
 
plugins
  .use(function (str) {
    return str + 'a';
  })
  .use(function (str) {
    return str + 'b';
  })
  .use(function (str) {
    return str + 'c';
  });
 
console.log(plugins.run('alphabet-'));
//=> 'alphabet-abc' 

Pass next as the last argument to run plugins asynchronously.

Example:

var plugins = new Plugins();
 
plugins
  .use(function (strnext) {
    next(null, str + 'a');
  })
  .use(function (strnext) {
    next(null, str + 'b');
  })
  .use(function (strnext) {
    next(null, str + 'c');
  });
 
plugins.run('alphabet-', function (errstr) {
  console.log(str); //=> 'alphabet-abc' 
});

To run plugins without .use(), pass an array of functions as a section argument to .run().

sync example:

var plugins = new Plugins();
 
var a = function(val) {
  return val + 'a';
};
var b = function(val) {
  return val + 'b';
};
var c = function(val) {
  return val + 'c';
};
 
console.log(plugins.run('alphabet-', [a, b, c]));
//=> 'alphabet-abc' 

async example:

var plugins = new Plugins();
 
var a = function (strnext) {
  next(null, str + 'a');
};
var b = function (strnext) {
  next(null, str + 'b');
};
var c = function (strnext) {
  next(null, str + 'c');
};
 
plugins.run('alphabet-', [a, b, c], function (errstr) {
  console.log(str); //=> 'alphabet-abc' 
});

See the examples.

Plugins

Initialize Plugins

Example

var Plugins = require('plugins');
var plugins = new Plugins();

.use

Add a plugin fn to the plugins stack.

Params

  • fn {Function}: Plugin function to add to the plugins stack.
  • returns {Object} Plugins: to enable chaining.

Example

plugins
  .use(foo)
  .use(bar)
  .use(baz)

.run

Call each fn in the plugins stack to iterate over val.

Params

  • val {Array|Object|String}: The value to iterate over.

Example

plugins.run(value)

.iterator

Register an iterator fn by its type.

Params

  • type {String}: The iterator type.
  • fn {Function}: Iterator function

.pipeline

Add each plugin to a pipeline to be used with streams. Plugins must either be a stream or a function that returns a stream.

Params

  • val {Array|Object|String}: The value to iterate over.

Example

var pipeline = plugins.pipeline(plugin());

async-array-reduce: Async reduce.

Install dev dependencies:

$ npm i -d && npm test

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Jon Schlinkert

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on August 14, 2015.