callsites

  • Version 4.2.0
  • Published
  • 7.13 kB
  • No dependencies
  • MIT license

Install

npm i callsites
yarn add callsites
pnpm add callsites

Overview

Get callsites from the V8 stack trace API

Index

Functions

function callsites

callsites: () => CallSite[];
  • Get callsites from the V8 stack trace API.

    Returns

    An array of CallSite objects.

    Example 1

    import callsites from 'callsites';
    function unicorn() {
    console.log(callsites()[0].getFileName());
    //=> '/Users/sindresorhus/dev/callsites/test.js'
    }
    unicorn();

Interfaces

interface CallSite

interface CallSite {}

    method getColumnNumber

    getColumnNumber: () => number | null;
    • Returns the current column number if this function was defined in a script.

    method getEvalOrigin

    getEvalOrigin: () => string | undefined;
    • Returns a string representing the location where eval was called if this function was created using a call to eval.

    method getFileName

    getFileName: () => string | null;
    • Returns the name of the script if this function was defined in a script.

    method getFunction

    getFunction: () => AnyFunction | undefined;
    • Returns the current function.

    method getFunctionName

    getFunctionName: () => string | null;
    • 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.

    method getLineNumber

    getLineNumber: () => number | null;
    • Returns the current line number if this function was defined in a script.

    method getMethodName

    getMethodName: () => string | undefined;
    • Returns the name of the property of this or one of its prototypes that holds the current function.

    method getPromiseIndex

    getPromiseIndex: () => number | null;
    • Returns the index of the promise element that was followed in Promise.all() or Promise.any() for async stack traces, or null if the CallSite is not an asynchronous Promise.all() or Promise.any() call.

    method getThis

    getThis: () => unknown | undefined;
    • Returns the value of this.

    method getTypeName

    getTypeName: () => string | null;
    • 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.

    method isAsync

    isAsync: () => boolean;
    • Returns true if this call is asynchronous (i.e. await, Promise.all(), or Promise.any()).

    method isConstructor

    isConstructor: () => boolean;
    • Returns true if this is a constructor call.

    method isEval

    isEval: () => boolean;
    • Returns true if this call takes place in code defined by a call to eval.

    method isNative

    isNative: () => boolean;
    • Returns true if this call is in native V8 code.

    method isPromiseAll

    isPromiseAll: () => boolean;
    • Returns true if this is an asynchronous call to Promise.all().

    method isToplevel

    isToplevel: () => boolean;
    • Returns true if this is a top-level invocation, that is, if it's a global object.

    Type Aliases

    type AnyFunction

    type AnyFunction = (...args: any[]) => any;

      Package Files (1)

      Dependencies (0)

      No dependencies.

      Dev Dependencies (3)

      Peer Dependencies (0)

      No peer dependencies.

      Badge

      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/callsites.

      • Markdown
        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/callsites)
      • HTML
        <a href="https://www.jsdocs.io/package/callsites"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>