Socket
Socket
Sign inDemoInstall

caller-callsite

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    caller-callsite

Get the callsite of the caller function


Version published
Weekly downloads
4.7M
decreased by-18.55%
Maintainers
1
Install size
13.6 kB
Created
Weekly downloads
 

Package description

What is caller-callsite?

The caller-callsite npm package allows developers to retrieve information about the call site of the function that called the current function. This can be particularly useful for debugging, logging, and tracking the flow of execution in complex applications. It leverages the V8 stack trace API to provide detailed information about the caller's location in the code.

What are caller-callsite's main functionalities?

Getting caller call site information

This feature allows developers to obtain information about the call site of the function that called the current function. The code sample demonstrates how to use caller-callsite to get the file name and line number of the caller function.

const callerCallsite = require('caller-callsite');

function demoFunction() {
  const callSite = callerCallsite();
  console.log(callSite.getFileName()); // prints the file name of the caller
  console.log(callSite.getLineNumber()); // prints the line number of the caller
}

function callerFunction() {
  demoFunction();
}

callerFunction();

Other packages similar to caller-callsite

Readme

Source

caller-callsite

Get the callsite of the caller function

Install

npm install caller-callsite

Usage

// foo.js
import callerCallsite from 'caller-callsite';

export default function foo() {
	console.log(callerCallsite().getFileName());
	//=> '/Users/sindresorhus/dev/unicorn/bar.js'
}
// bar.js
import foo from './foo.js';
foo();

API

callerCallsite(options?)

Returns a callsite object.

options

Type: object

depth

Type: number
Default: 0

The callsite depth, meaning how many levels we follow back on the stack trace.

For example:

// foo.js
import callerCallsite from 'caller-callsite';

export default function foo() {
	console.log(callerCallsite().getFileName());
	//=> '/Users/sindresorhus/dev/unicorn/foobar.js'
	console.log(callerCallsite({depth: 1}).getFileName());
	//=> '/Users/sindresorhus/dev/unicorn/bar.js'
	console.log(callerCallsite({depth: 2}).getFileName());
	//=> '/Users/sindresorhus/dev/unicorn/foo.js'
}
// bar.js
import foo from './foo.js';

export default function foo() {
	foo();
}
// foobar.js
import bar from './bar.js';
bar();

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

Last updated on 07 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc