UNPKG

1.9 kBMarkdownView Raw
1# callsites [![Build Status](https://travis-ci.org/sindresorhus/callsites.svg?branch=master)](https://travis-ci.org/sindresorhus/callsites)
2
3> Get callsites from the [V8 stack trace API](https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi)
4
5
6## Install
7
8```sh
9$ npm install --save callsites
10```
11
12
13## Usage
14
15```js
16var callsites = require('callsites');
17
18function unicorn() {
19 console.log(callsites()[0].getFileName());
20 //=> /Users/sindresorhus/dev/callsites/test.js
21}
22
23unicorn();
24```
25
26## API
27
28Returns an array of callsite objects with the following methods:
29
30- `getThis`: returns the value of this
31- `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.
32- `getFunction`: returns the current function
33- `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.
34- `getMethodName`: returns the name of the property of this or one of its prototypes that holds the current function
35- `getFileName`: if this function was defined in a script returns the name of the script
36- `getLineNumber`: if this function was defined in a script returns the current line number
37- `getColumnNumber`: if this function was defined in a script returns the current column number
38- `getEvalOrigin`: if this function was created using a call to eval returns a CallSite object representing the location where eval was called
39- `isToplevel`: is this a toplevel invocation, that is, is this the global object?
40- `isEval`: does this call take place in code defined by a call to eval?
41- `isNative`: is this call in native V8 code?
42- `isConstructor`: is this a constructor call?
43
44
45## License
46
47MIT © [Sindre Sorhus](http://sindresorhus.com)