UNPKG

1.16 kBTypeScriptView Raw
1export interface Options {
2 /**
3 The caller path depth, meaning how many levels we follow back on the stack trace.
4
5 @default 0
6
7 @example
8 ```
9 // foo.ts
10 import callerPath from 'caller-path';
11
12 export default function foo() {
13 console.log(callerPath());
14 //=> '/Users/sindresorhus/dev/unicorn/foobar.ts'
15 console.log(callerPath({depth: 1}));
16 //=> '/Users/sindresorhus/dev/unicorn/bar.ts'
17 console.log(callerPath({depth: 2}));
18 //=> '/Users/sindresorhus/dev/unicorn/foo.ts'
19 }
20
21 // bar.ts
22 import foo from './foo.js';
23
24 export default function bar() => {
25 foo();
26 }
27
28 // foobar.ts
29 import bar from './bar.js';
30 bar();
31 ```
32 */
33 readonly depth?: number;
34}
35
36/**
37Get the path of the caller function.
38
39If the caller's [callsite](https://github.com/sindresorhus/callsites#api) object `getFileName` was not defined for some reason, it will return `undefined`.
40
41@example
42```
43// foo.ts
44import callerPath from 'caller-path';
45
46export default function foo() {
47 console.log(callerPath());
48 //=> '/Users/sindresorhus/dev/unicorn/bar.ts'
49}
50
51// bar.ts
52import foo from './foo.js';
53foo();
54```
55*/
56export default function callerPath(options?: Options): string | undefined;
57