caller-path

WebJar for caller-path

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

caller-path
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

caller-path
WebJar for caller-path
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/sindresorhus/caller-path

Download caller-path

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/caller-path/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>caller-path</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/caller-path/
implementation 'org.webjars.npm:caller-path:2.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/caller-path/
implementation ("org.webjars.npm:caller-path:2.0.0")
'org.webjars.npm:caller-path:jar:2.0.0'
<dependency org="org.webjars.npm" name="caller-path" rev="2.0.0">
  <artifact name="caller-path" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='caller-path', version='2.0.0')
)
libraryDependencies += "org.webjars.npm" % "caller-path" % "2.0.0"
[org.webjars.npm/caller-path "2.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : caller-callsite jar [2.0.0,3)

Project Modules

There are no modules declared in this project.

caller-path

Get the path of the caller function

Important: You have to use 'use strict'; in your code for this module to work correctly, or make sure the module is an ESM module, which is implicitly strict.

Install

$ npm install caller-path

Usage

// foo.js
const callerPath = require('caller-path');

module.exports = () => {
	console.log(callerPath());
	//=> '/Users/sindresorhus/dev/unicorn/bar.js'
}
// bar.js
const foo = require('./foo');
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
const callerPath = require('caller-path');

module.exports = () => {
	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
const foo = require('./foo');

module.exports = () => {
	foo();
}
// foobar.js
const bar = require('./bar');
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.

Versions

Version
2.0.0
0.1.0