https://github.com/stringparser/callers-module
caller's module information
https://github.com/stringparser/callers-module
Last synced: 11 months ago
JSON representation
caller's module information
- Host: GitHub
- URL: https://github.com/stringparser/callers-module
- Owner: stringparser
- Created: 2014-10-03T11:17:31.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-10-13T09:19:38.000Z (over 11 years ago)
- Last Synced: 2024-10-17T03:40:06.747Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 199 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# callers-module [
](https://github.com/fehmicansaglam/progressed.io)
[
](https://travis-ci.org/stringparser/callers-module/builds)
[
](http://www.npmjs.org/package/callers-module)
[V8 stacktrace API](https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi) based caller's module information
## install
npm install --save callers-module
## usage
```js
var path = require('path');
var callersModule = require('callers-module');
// $ mocha test/fileName.js
module.exports = function(){
it('should give callers module', function(){
console.log(callersModule());
// => {
// module : 'mocha',
// scope : 'mocha/lib',
// path : '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 stack is sliced by one.
## 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
- [visionmedia `callsite`](https://github.com/visionmedia/callsite)
- [sindresorhus `callsites`](https://github.com/sindresorhus/callsites)
- [sindresorhus `caller-path`](https://github.com/sindresorhus/caller-path)
## test
npm test
### license
[
](http://opensource.org/licenses/MIT)