cept

Intercept method calls

Usage no npm install needed!

<script type="module">
  import cept from 'https://cdn.skypack.dev/cept';
</script>

README

cept

Build Coverage Downloads Size

Intercept method calls.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

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 object
  • key (string) — Field where the original method lives
  • callback (Function) - Interceptor
Returns

Function — Used to revert back to the previous function.

License

MIT © Titus Wormer