@othon/interceptorjs

The simple module to interceptor method

Stats

StarsIssuesVersionUpdatedCreatedSize
@othon/interceptorjs
1.1.63 years ago3 years agoMinified + gzip package size for @othon/interceptorjs in KB

Readme

interceptorjs

The simple module to interceptor method

Installing

API

interceptor(
  instance,
  methodName,
  options:{
    beforeFn:<Object or Array>,
    afterFn:<Object or Array>,
  }
)

Example

Using single before trigger method

const moduleInstace = require('moduleInstace')
const beforeFn ()=> console.log('before')

interceptor(moduleInstace,'methodName',{beforeFn})

Using array before trigger method

const moduleInstace = require('moduleInstace')
const beforeFn = [
  ()=> console.log('before1'),
  ()=> console.log('before2'),
  ()=> console.log('before3'),
]

interceptor(moduleInstace,'methodName',{beforeFn})

Using regex to select all methods

...
interceptor(moduleTest,'.*',{beforeFn:beforeFn1})
...

Using regex to select few methods

interceptor(moduleTest,'methodA|methodB',{beforeFn:beforeFn1})

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.