js-interceptor
v1.1.0
Published
A JavaScript application interceptor implementation.
Downloads
3
Readme
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)
})