UNPKG

2.08 kBTypeScriptView Raw
1type AnyFunction = (...args: any[]) => any;
2
3export interface CallSite {
4 /**
5 Returns the value of `this`.
6 */
7 getThis(): unknown | undefined;
8
9 /**
10 Returns the type of `this` as a string. This is the name of the function stored in the constructor field of `this`, if available, otherwise the object's `[[Class]]` internal property.
11 */
12 getTypeName(): string | null;
13
14 /**
15 Returns the current function.
16 */
17 getFunction(): AnyFunction | undefined;
18
19 /**
20 Returns the name of the current function, typically its `name` property. If a name property is not available an attempt will be made to try to infer a name from the function's context.
21 */
22 getFunctionName(): string | null;
23
24 /**
25 Returns the name of the property of `this` or one of its prototypes that holds the current function.
26 */
27 getMethodName(): string | undefined;
28
29 /**
30 Returns the name of the script if this function was defined in a script.
31 */
32 getFileName(): string | null;
33
34 /**
35 Returns the current line number if this function was defined in a script.
36 */
37 getLineNumber(): number | null;
38
39 /**
40 Returns the current column number if this function was defined in a script.
41 */
42 getColumnNumber(): number | null;
43
44 /**
45 Returns a string representing the location where `eval` was called if this function was created using a call to `eval`.
46 */
47 getEvalOrigin(): string | undefined;
48
49 /**
50 Returns `true` if this is a top-level invocation, that is, if it's a global object.
51 */
52 isToplevel(): boolean;
53
54 /**
55 Returns `true` if this call takes place in code defined by a call to `eval`.
56 */
57 isEval(): boolean;
58
59 /**
60 Returns `true` if this call is in native V8 code.
61 */
62 isNative(): boolean;
63
64 /**
65 Returns `true` if this is a constructor call.
66 */
67 isConstructor(): boolean;
68}
69
70/**
71Get callsites from the V8 stack trace API.
72
73@returns An array of `CallSite` objects.
74
75@example
76```
77import callsites from 'callsites';
78
79function unicorn() {
80 console.log(callsites()[0].getFileName());
81 //=> '/Users/sindresorhus/dev/callsites/test.js'
82}
83
84unicorn();
85```
86*/
87export default function callsites(): CallSite[];