Skip to content

keshav-bohr/intermediary

 
 

Repository files navigation

Intermediary

Have hooks and middleware for just about any function.

npm version build status bundle size

Features

  • Execute middleware before your function executes
  • Execute afterware after your function executes
  • Organize and compose repeated workflows
  • Asynchronous middleware and afterware support
  • Works in node as well as browser

Installing

Using NPM:

npm i intermediary

Using yarn:

yarn add intermediary

UMD Build CDN:

<script src="https://cdn.jsdelivr.net/npm/intermediary/lib/intermediary.min.js"></script>

Importing

Common JS:

const Intermediary = require('intermediary')

ES6:

import Intermediary from 'intermediary';

Browser:

If using the CDN, Intermediary is available at window.Intermediary.

Migrating from 1.x to 2.x

  • Middleware and Afterware executor is removed. Therefore, no use of a executor function that takes a next argument and return the next(args)

  • In middleware, instead of returning next(args), return [...args] in an array form

  • In afterware, instead of returning next(args), return {result: <result to be used by next afterware>, args: <arguments to be used by next afterware>}

  • Afterware callback takes result from previous afterware/target as first argument and remaining arguments with it

  • Extra argument as config can be sent to involve or series. It includes the flag for throwOnMiddleware, throwOnTarget, throwOnAfterware that help in execution of the middleware/afterware/target even if there is any error that occurs in any of them, according the flags provided

About

Universally applicable middleware

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%