nanomiddleware
v1.0.0
Published
Simple middleware engine
Downloads
1
Readme
nanomiddleware
Simple middleware engine
Table of Contents
Install
This project uses node and npm.
$ npm install nanomiddleware
$ # OR
$ yarn add nanomiddleware
Usage
import Middleware from 'nanomiddleware'
const mid = new Middleware()
function sleep (time = 500) {
return new Promise((resolve) => {
setTimeout(resolve, 500)
})
}
mid.use(async function (...args) {
await sleep()
console.log(args)
return 5
})
mid.use(async function (...args) {
await sleep(1000)
console.log(args)
return 8
})
mid.use([1, 2, 3, 4, async function (...args) {
await sleep(1000)
console.log(args)
return {success: true}
}])
mid.use(async function (...args) {
await sleep(400)
console.log('Ran first', args)
return 100
}, {before: true})
mid.run('hi')
// Ran first [ 'hi' ]
// [ 100 ]
// [ 5 ]
// [ 4 ]
Contribute
- Fork it and create your feature branch: git checkout -b my-new-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request
License
MIT