nanomiddleware

1.0.0 • Public • Published

nanomiddleware

package version package downloads standard-readme compliant package license make a pull request

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

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am 'Add some feature'
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT

Dependents (1)

Package Sidebar

Install

npm i nanomiddleware

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

10.4 kB

Total Files

11

Last publish

Collaborators

  • tiaanduplessis