🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

caller-callsite

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caller-callsite

Get the callsite of the caller function

latest
Source
npmnpm
Version
6.0.0
Version published
Weekly downloads
6.4M
-4.09%
Maintainers
1
Weekly downloads
 
Created
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 from the caller.

For example:

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

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

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

Keywords

caller

FAQs

Package last updated on 21 Sep 2025

Did you know?

Socket

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