Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

EvgenyOrekhov/functrace

Repository files navigation

functrace

Travis CI build status Codacy grade

Function call tracer

Install

npm install functrace --save-dev

Usage example

const functrace = require("functrace");
const trace = functrace.makeTracer();

function add(a, b) {
    return a + b;
}

const tracedAdd = trace(add);

tracedAdd(1, 2);

/* logs to console:

{ name: 'add',
  args: [ 1, 2 ],
  callCount: 1,
  returnValue: 3,
  duration: '42 μs' }

*/

/* It can also trace functions that return promises */

function addAsync(a, b) {
    return new Promise(
        (resolve) => setTimeout(() => resolve(a + b), 1000)
    );
}

const tracedAddAsync = trace(addAsync);

tracedAddAsync(1, 2);

/* logs to console one second later:

{ name: 'addAsync',
  args: [ 1, 2 ],
  callCount: 1,
  fulfillmentValue: 3,
  duration: '1 s' }

*/

Test

npm test

License

MIT