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