An open API service indexing awesome lists of open source software.

https://github.com/stringparser/callers-path

V8 stacktrace API based caller's path
https://github.com/stringparser/callers-path

Last synced: 6 months ago
JSON representation

V8 stacktrace API based caller's path

Awesome Lists containing this project

README

          

# callers-path

[build](https://travis-ci.org/stringparser/callers-path/builds)
[NPM version](http://www.npmjs.org/package/callers-path)

[V8 stacktrace API](https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi) based caller's path

## install

npm install --save callers-path

## usage

example/moduleB.js
```js
var callersPath = require('callers-path');
module.exports = function(){
console.log(callersPath());
};
```

example/moduleA.js

```js
var moduleB = require('./moduleB');
moduleB();
// => example/moduleA.js
```

### documentation

`require('callers-path')([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

[LICENSE](http://opensource.org/licenses/MIT)