1 | # callsites
|
2 |
|
3 | > Get callsites from the [V8 stack trace API](https://v8.dev/docs/stack-trace-api)
|
4 |
|
5 | ## Install
|
6 |
|
7 | ```
|
8 | $ npm install callsites
|
9 | ```
|
10 |
|
11 | ## Usage
|
12 |
|
13 | ```js
|
14 | import callsites from 'callsites';
|
15 |
|
16 | function unicorn() {
|
17 | console.log(callsites()[0].getFileName());
|
18 | //=> '/Users/sindresorhus/dev/callsites/test.js'
|
19 | }
|
20 |
|
21 | unicorn();
|
22 | ```
|
23 |
|
24 | ## API
|
25 |
|
26 | Returns an array of callsite objects with the following methods:
|
27 |
|
28 | - `getThis`: Returns the value of `this`.
|
29 | - `getTypeName`: 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.
|
30 | - `getFunction`: Returns the current function.
|
31 | - `getFunctionName`: 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.
|
32 | - `getMethodName`: Returns the name of the property of `this` or one of its prototypes that holds the current function.
|
33 | - `getFileName`: If this function was defined in a script returns the name of the script.
|
34 | - `getLineNumber`: If this function was defined in a script returns the current line number.
|
35 | - `getColumnNumber`: If this function was defined in a script returns the current column number
|
36 | - `getEvalOrigin`: If this function was created using a call to `eval` returns a string representing the location where `eval` was called.
|
37 | - `isToplevel`: Is this a top-level invocation, that is, is this the global object?
|
38 | - `isEval`: Does this call take place in code defined by a call to `eval`?
|
39 | - `isNative`: Is this call in native V8 code?
|
40 | - `isConstructor`: Is this a constructor call?
|
41 |
|
42 | ---
|
43 |
|
44 | <div align="center">
|
45 | <b>
|
46 | <a href="https://tidelift.com/subscription/pkg/npm-callsites?utm_source=npm-callsites&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
47 | </b>
|
48 | <br>
|
49 | <sub>
|
50 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
51 | </sub>
|
52 | </div>
|