@parkhub/circe-middleware
v1.1.0
Published
A simple middleware module that you know and love. Using the "next" pattern means you can have async/sync middleware!
Downloads
10
Maintainers
Keywords
Readme
Circe Middleware
A simple middleware module that you know and love. Using the "next" pattern means you can have async/sync middleware!
Install
npm install @parkhub/circe-middleware
Usage
import circeMiddleware from '@parkhub/circe-middleware';
const middlewareFnOne = (value, next) => {
// value is 'starting value'
// Call next and pass params with any arity(as long as next middleware expects the same arity)
next('Satsuki!');
};
const middlewareFnTwo = (value, next) => {
// Value is 'Satsuki!'
// Call next and pass params with any arity(as long as next middleware expects the same arity)
next({ going: 'gone' }, 1);
};
const middlewareFnThree = (obj, int, next) => {
// obj is { going: 'gone' } and int is 1
next('done');
}
// The middleware is executed in the order of the passed array
const middleware = circeMiddleware([middlewareFnOne, middlewareFnTwo]);
// This middleware will be executed after the first two passed into the middleware factory
middleware.use(middlewareFnThree);
middleware.run('starting value', (finalValue) => {
// finalValue is 'done'
});
Middlewares
A middleware is a function that receives an arbitrary number of parameters with the last one being the next function. You have to be conscious of the order of the middlware and what it accepts as parameters
API
use(middlewareFn)
middlewareFn - a function with signature of (arg1, arg2, ...argX, next)
Adds a middleware to the middleware stack.