JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 32
  • Score
    100M100P100Q48501F
  • License MIT

v8 callsite-based caller's module with knobs

Package Exports

  • callers-module

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (callers-module) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

callers-module progressed.io

build NPM version

V8 stacktrace API based caller's path

install

npm install --save callers-module

usage

var path = require('path');
var callersModule = require('callers-module');

// mocha test/fileName.js
module.exports = function(){
  console.log(callersModule());
  // => {
  //    module : 'mocha',
  //     scope : 'mocha/lib',
  //  filename : 'node_modules/mocha/lib/runnable.js',
  //  location : 'node_modules/mocha/lib/runnable.js:249:21'
  // };
}

documentation

require('callers-module')([frames, origin])

  • frames if specified should be an integer bigger than 0 or Infinity.
  • origin if specified should be a function.
  • if no arguments, the default number of frames is 2 so the origin is the module itself. The returned stack is sliced by one.

See also the avaliable methods of the stack trace api like:

  • getLineNumber
  • getFileName
  • getEvalOrigin
  • etc.

why

You would like to set how many frames are recorded (Error.stackTraceLimit) and from which function the stack should be traced back (Error.captureStackTrace).

By default two frames are recorded, though you can even lower it to one providing a function from which start.

inspirated by

It serves for the same use cases implemented on this cool modules

test

npm test

license

LICENSE