caller-path
Advanced tools
Comparing version 2.0.0 to 3.0.0
'use strict'; | ||
const callerCallsite = require('caller-callsite'); | ||
module.exports = () => callerCallsite().getFileName(); | ||
module.exports = ({depth = 0} = {}) => callerCallsite({depth}).getFileName(); |
{ | ||
"name": "caller-path", | ||
"version": "2.0.0", | ||
"description": "Get the path of the caller function", | ||
"license": "MIT", | ||
"repository": "sindresorhus/caller-path", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"caller", | ||
"calling", | ||
"module", | ||
"path", | ||
"parent", | ||
"callsites", | ||
"callsite", | ||
"stacktrace", | ||
"stack", | ||
"trace", | ||
"function", | ||
"file" | ||
], | ||
"dependencies": { | ||
"caller-callsite": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "caller-path", | ||
"version": "3.0.0", | ||
"description": "Get the path of the caller function", | ||
"license": "MIT", | ||
"repository": "sindresorhus/caller-path", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"caller", | ||
"calling", | ||
"module", | ||
"path", | ||
"parent", | ||
"callsites", | ||
"callsite", | ||
"stacktrace", | ||
"stack", | ||
"trace", | ||
"function", | ||
"file" | ||
], | ||
"dependencies": { | ||
"caller-callsite": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.25.3" | ||
} | ||
} |
@@ -5,2 +5,3 @@ # caller-path [![Build Status](https://travis-ci.org/sindresorhus/caller-path.svg?branch=master)](https://travis-ci.org/sindresorhus/caller-path) | ||
**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. | ||
@@ -10,6 +11,5 @@ ## Install | ||
``` | ||
$ npm install --save caller-path | ||
$ npm install caller-path | ||
``` | ||
## Usage | ||
@@ -33,5 +33,58 @@ | ||
If the caller's [callsite](https://github.com/sindresorhus/callsites#api) object `getFileName` was not defined for some reason, it will return `undefined`. | ||
## License | ||
## API | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
### 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: | ||
```js | ||
// 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' | ||
} | ||
``` | ||
```js | ||
// bar.js | ||
const foo = require('./foo'); | ||
module.exports = () => { | ||
foo(); | ||
} | ||
``` | ||
```js | ||
// foobar.js | ||
const bar = require('./bar'); | ||
bar(); | ||
``` | ||
--- | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-caller-path?utm_source=npm-caller-path&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
Sorry, the diff of this file is not supported yet
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
5119
5
51
88
0
3
+ Addedcaller-callsite@4.1.0(transitive)
+ Addedcallsites@3.1.0(transitive)
- Removedcaller-callsite@2.0.0(transitive)
- Removedcallsites@2.0.0(transitive)
Updatedcaller-callsite@^4.1.0