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

co-ware

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-ware

Ware inspired, easily create your own middleware layer using generators via co.

  • 1.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
669
increased by15.15%
Maintainers
1
Weekly downloads
 
Created
Source

co-ware Build Status

Ware inspired, easily create your own middleware layer using generators via co.

Examples

var ware = require('..');
var w = ware()
  .use(function *(next) {
    this.x = 'hello';
    yield next;
  })
  .use(function *(next) {
    this.y = 'world';
    yield next;
  })
  .use(function *(next) {
    yield next;
  });

w.run({}, {}, function *() {
  console.log(this.x, this.y);
});

Print the arguments of input.

var ware = require('..');
var w = ware()
  .use(function *(next) {
    console.log(this.input); // 1, 2, 3
    yield next;
  });

w.run(1, 2, 3);

Handles error.

var ware = require('..');
var w = ware()
  .use(function *(next) {
    if ('42' != this.input[0].life) throw new Error();
    yield next;
  })
  .use(function *(next) {
    console.log('yes!');
  })
  .on('error', function (err) {
    console.log('no!');
  });

w.run({ life: '41' }); // "no!"
w.run({ life: '42' }); // "yes!"

API

ware()

Create a new list of middleware.

.use(*fun)

Push a middleware fn(GeneratorFunction) onto the list. If the middleware has an arity of one more than the input to run it's an error middleware.

.run(input..., [*callback|callback])

Runs the middleware functions with input... and optionally calls callback(GeneratorFunction or Function).

.clear()

Clear the middleware.

License

MIT

Keywords

FAQs

Package last updated on 23 Aug 2014

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