caller
@substack's caller.js as a module
Last updated 9 years ago by totherik .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install caller 
SYNC missed versions from official npm registry.

caller

Figure out your caller (thanks to @substack).

Initialization Time Caller
// foo.js

var bar = require('bar');
// bar.js

var caller = require('caller');
console.log(caller()); // `/path/to/foo.js`
Runtime Caller
// foo.js

var bar = require('bar');
bar.doWork();
// bar.js

var caller = require('caller');

exports.doWork = function () {
    console.log(caller());  // `/path/to/foo.js`
};

Depth

Caller also accepts a depth argument for tracing back further (defaults to 1).

// foo.js

var bar = require('bar');
bar.doWork();
// bar.js

var baz = require('baz');

exports.doWork = function () {
    baz.doWork();
};
// baz.js

var caller = require('caller');

exports.doWork = function () {
    console.log(caller(2));  // `/path/to/foo.js`
};

Current Tags

  • 1.1.0                                ...           latest (3 years ago)

4 Versions

  • 1.1.0                                ...           3 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           10 years ago
  • 0.0.1                                ...           11 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE