README
cept
Intercept method calls.
Install
This package is ESM only: Node 12+ is needed to use it and it must be import
ed
instead of require
d.
npm:
npm install cept
Use
import {cept} from 'cept'
// Intercept:
var stop = cept(console, 'log', noop)
// From now on `console.log` is ignored:
console.log('foo bar baz')
// No longer ignored!
stop()
function noop() {}
API
This package exports the following identifiers: cept
.
There is no default export.
stop = cept(context, key, callback)
Intercept all calls to context[key]
(e.g., console.log
).
From now on, when the original method would be called, callback
is used
instead.
Calling stop
reverts everything back to normal.
Parameters
context
(Object
) — Context objectkey
(string
) — Field where the original method livescallback
(Function
) - Interceptor
Returns
Function
— Used to revert back to the previous function.