caller-path
Get the path of the caller function
Install
npm install caller-path
Usage
import callerPath from 'caller-path';
export default function foo() {
console.log(callerPath());
}
import foo from './foo.js';
foo();
If the caller's callsite object getFileName
was not defined for some reason, it will return undefined
.
API
callerPath(options?)
Get the path of the caller function.
depth
Type: number
Default: 0
The caller path depth, meaning how many levels we follow back on the stack trace.
For example:
import callerPath from 'caller-path';
export default function foo() {
console.log(callerPath());
console.log(callerPath({depth: 1}));
console.log(callerPath({depth: 2}));
}
import foo from './foo.js';
export default function bar() {
foo();
}
import bar from './bar.js';
bar();