You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

beware

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beware

Lightweight async/await middleware library (formerly middlewerewolf)

0.0.4
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Beware

Lightweight async/await middleware library (formerly middlewerewolf)

Installation

yarn add beware

Usage

import Beware from "beware";
let app = new Beware();

// This middleware will execute without issue
app.use(async (ctx, next) => {
  ctx.foo = true;
  await next();
});

// This middleware will execute, but does not call next()
app.use(async ctx => {
  ctx.bar = true;
});

// This middleware will not execute, as the previous middleware
// did not call next()
app.use(async ctx => {
  ctx.baz = true;
});

// Register multiple middleware with a single command
app.all([
  async ctx => {
    ctx.foo = true;
    await next();
  },
  async ctx => {
    ctx.bar = true;
    await next();
  }
]);

// Compose a new middleware execution chain
let fn = app.compose();

// Execute the chain
fn({
  initial_context: true
}).then(ctx => {
  console.log("All done here!");
}).catch(err => {
  console.log("Handle errors like a boss.");
});

Build beware

git clone git@github.com:aewing/beware.git
cd beware/
make lint
make flow
make test
make build

Contributing

Pull requests are welcome, but I intend to keep this package as lightweight and future compliant as possible.

Credits

Much love to koa-compose, which inspired this package.

Keywords

es6

FAQs

Package last updated on 02 Sep 2017

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