koa-if-else
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

koa-if-else

if

import koa from "koa";
import { ify } from "koa-if-else";

const app = new Koa();

app.use(
  ify(
    (ctx) => ctx.query.one,
    (ctx) => (ctx.state.result = "One!")
  ),
  (ctx) => (ctx.body = ctx.state.result)
);

if/else

import koa from "koa";
import { ify } from "koa-if-else";

const app = new Koa();

app.use(
  ify(
    (ctx) => ctx.query.one,
    (ctx) => (ctx.state.result = "One!")
  )
    .elsey((ctx) => (ctx.state.result = "Something else!"),
  (ctx) => (ctx.body = ctx.state.result)
);

if/elseif/else

import koa from "koa";
import { ify } from "koa-if-else";

const app = new Koa();

app.use(
  ify(
    (ctx) => ctx.query.one,
    (ctx) => (ctx.state.result = "One!")
  )
    .elseyIfy(
      (ctx) => ctx.query.two,
      (ctx) => (ctx.state.result = "Two!")
    )
    .elsey((ctx) => (ctx.state.result = "Something else!"),
  (ctx) => (ctx.body = ctx.state.result)
);

Package Sidebar

Install

npm i koa-if-else

Weekly Downloads

174

Version

0.0.3

License

MIT

Unpacked Size

15.9 kB

Total Files

12

Last publish

Collaborators

  • blackmarket