Socket
Socket
Sign inDemoInstall

caller-path

Package Overview
Dependencies
2
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

caller-path

Get the path of the caller function


Version published
Maintainers
1
Weekly downloads
6,668,103
increased by1.75%
Install size
19.6 kB

Weekly downloads

Readme

Source

caller-path

Get the path of the caller function

Install

npm install caller-path

Usage

// foo.js
import callerPath from 'caller-path';

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

If the caller's callsite object getFileName was not defined for some reason, it will return undefined.

API

callerPath(options?)

Get the path of the caller function.

depth

Type: number
Default: 0

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

For example:

// foo.js
import callerPath from 'caller-path';

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

export default function bar() {
	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 08 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