caller-callsite
Get the callsite of the caller function
Last updated a year ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install caller-callsite 
SYNC missed versions from official npm registry.

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();

Current Tags

  • 6.0.0                                ...           latest (a year ago)

8 Versions

  • 6.0.0                                ...           a year ago
  • 5.0.0                                ...           5 years ago
  • 4.1.0                                ...           7 years ago
  • 4.0.0                                ...           8 years ago
  • 3.0.0                                ...           9 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 13
Today 0
This Week 2
This Month 9
Last Day 0
Last Week 6
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE