npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plugins

v0.4.2

Published

Run a value through a plugin stack.

Downloads

4,222

Readme

plugins NPM version

Run a value through a plugin stack.

Install

Install with npm

$ npm i plugins --save

See the examples.

Table of contents

(Table of contents generated by verb)

Docs

See the examples.

Creating plugins

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

sync

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'

async

Pass next as the last argument to run plugins asynchronously.

Example:

var plugins = new Plugins();

plugins
  .use(function (str, next) {
    next(null, str + 'a');
  })
  .use(function (str, next) {
    next(null, str + 'b');
  })
  .use(function (str, next) {
    next(null, str + 'c');
  });

plugins.run('alphabet-', function (err, str) {
  console.log(str); //=> 'alphabet-abc'
});

Directly run plugins

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 (str, next) {
  next(null, str + 'a');
};
var b = function (str, next) {
  next(null, str + 'b');
};
var c = function (str, next) {
  next(null, str + 'c');
};

plugins.run('alphabet-', [a, b, c], function (err, str) {
  console.log(str); //=> 'alphabet-abc'
});

API

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());

Related projects

async-array-reduce: Async reduce.

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

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

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


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