Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

koa-or-and

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-or-and

```javascript const Koa = require('koa'); const { or, and } = require('koa-or-and');

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

koa or and middleware

const Koa = require('koa');
const { or, and } = require('koa-or-and');

const app = new Koa();

function fail1(ctx, next) {
  console.log('fail1');
  throw new Error('fail1');
}

function fail2(ctx, next) {
  console.log('fail2');
  throw new Error('fail2');
}

function success1(ctx, next) {
  console.log('success1');
  return next();
}

function success2(ctx, next) {
  console.log('success2');
  return next();
}

app.use(or(fail1, fail2, and(success1, fail1), success2));

app.use(async ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

output:

fail1
fail2
success1
fail1
success2

Keywords

web

FAQs

Package last updated on 10 Nov 2021

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