New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

observe-function

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

observe-function

Observe when a function is called and assign callbacks before and after the function is called.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

observe-function

Observe when a function is called and assign callbacks before and after the function is called.

Install

$ npm install --save observe-function

Usage

var observeFunction = require('observe-function');

var observedFunction = function (arg1, arg2){
  console.log('I am observed');
  return arg1 + arg2;
};

//Simply wrap the function you want to observe
var observer = observeFunction(observedFunction);

//assign callback to be called before function executes
observer.before(function(){
  console.log('I am called before');
});

//... and after it executes
observer.after(function(){
  console.log('I am called after');
});

//call the observer just as you would the regular function
var three = observer(1, 2);
//=>I am called before
//=>I am observed
//=>I am called after

console.log(three);
//=> 3

API

observeFunction(anyFunction)

Assigns the function to be observed. Returns a function that can be called just like the provided function.

observer.before(callback)

Assigns a callback to be called before the function is called. An observer can be assigned multiple "before" callbacks.

observer.after(callback)

Assigns a callback to be called after the function is called. An observer can be assigned multiple "after" callbacks.

observer.remove.before(callback)

Removes the specified callback from the list of "before" callbacks

observer.remove.after(callback)

Removes the specified callback from the list of "after" callbacks

observer.reset.before()

Removes all callbacks from the list of "before" callbacks

observer.reset.after()

Removes all callbacks from the list of "after" callbacks

observer.reset.all()

Removes all "before" and "after" callbacks

Keywords

observe

FAQs

Package last updated on 13 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts