caller-path
- Version 4.0.0
- Published
- 4.98 kB
- 1 dependency
- MIT license
Install
npm i caller-path
yarn add caller-path
pnpm add caller-path
Overview
Get the path of the caller function
Index
Functions
Interfaces
Functions
function callerPath
callerPath: (options?: Options) => string | undefined;
Get the path of the caller function.
If the caller's [callsite](https://github.com/sindresorhus/callsites#api) object
getFileName
was not defined for some reason, it will returnundefined
.Example 1
// foo.tsimport callerPath from 'caller-path';export default function foo() {console.log(callerPath());//=> '/Users/sindresorhus/dev/unicorn/bar.ts'}// bar.tsimport foo from './foo.js';foo();
Interfaces
interface Options
interface Options {}
property depth
readonly depth?: number;
The caller path depth, meaning how many levels we follow back on the stack trace.
0
Example 1
``` // foo.ts import callerPath from 'caller-path';
export default function foo() { console.log(callerPath()); //=> '/Users/sindresorhus/dev/unicorn/foobar.ts' console.log(callerPath({depth: 1})); //=> '/Users/sindresorhus/dev/unicorn/bar.ts' console.log(callerPath({depth: 2})); //=> '/Users/sindresorhus/dev/unicorn/foo.ts' }
// bar.ts import foo from './foo.js';
export default function bar() => { foo(); }
// foobar.ts import bar from './bar.js'; bar(); ```
Package Files (1)
Dependencies (1)
Dev Dependencies (4)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/caller-path
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/caller-path)
- HTML<a href="https://www.jsdocs.io/package/caller-path"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2528 ms. - Missing or incorrect documentation? Open an issue for this package.