1.0.2 • Published 5 years ago

functrace v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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

Changelog

License

MIT

1.0.2

5 years ago

1.0.1

7 years ago

1.0.0

7 years ago