caller-callsite
Get the callsite of the caller function
Install
npm install caller-callsite
Usage
import callerCallsite from 'caller-callsite';
export default function foo() {
console.log(callerCallsite().getFileName());
}
import foo from './foo.js';
foo();
API
callerCallsite(options?)
Returns a callsite
object.
options
Type: object
depth
Type: number
Default: 0
The callsite depth, meaning how many levels we follow back on the stack trace.
For example:
import callerCallsite from 'caller-callsite';
export default function foo() {
console.log(callerCallsite().getFileName());
console.log(callerCallsite({depth: 1}).getFileName());
console.log(callerCallsite({depth: 2}).getFileName());
}
import foo from './foo.js';
export default function foo() {
foo();
}
import bar from './bar.js';
bar();