1.1.0 • Published 6 years ago

js-interceptor v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

js-interceptor

A JavaScript application interceptor implementation.

npm

npm install -S js-interceptor

use

import interceptor from 'js-interceptor'

const exec = interceptor(middlewares)

exec(function (content) {
  // do...
})

example

const interceptor = require('./')

const obj = {
  middlewares: [],
  use (fn) {
    this.middlewares.push(fn)
  }
}

obj.use(function (ctx, next) {
  console.log('1')
  console.log(ctx)

  ctx.age++
  ctx.fullName = ctx.firstName + '●' + ctx.lastName

  next()
})

obj.use(function (ctx, next) {
  console.log('2')
  console.log(ctx)

  next()
})

interceptor(obj.middlewares)({firstName: 'Sharon', lastName: 'Jackson', age: 21}, function (ctx) {
  console.log(3)
  console.log(ctx)
})
1.1.0

6 years ago

1.0.0

6 years ago