Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
caller-dirname
Advanced tools
Get the directory name of a caller function's containing file.
$ npm i caller-dirname
/home/detrohutt/test/caller-dirname/callee.js
import callerDirname from 'caller-dirname';
export default () => callerDirname();
/home/detrohutt/test/caller-dirname/deeper/caller.js
import thisDirname from '../callee.js';
console.log(thisDirname()); /* /home/detrohutt/test/caller-dirname/deeper */
Option | Default | Description |
---|---|---|
depth | 1 | Depth sets the position in the call stack at which you want to retrieve the directory name. With the default depth of 1 (1st caller) you get the dirname of the function that directly calls callerDirname() (we'll call it fn1 ). With a depth of 2 (2nd caller), you'd instead get the dirname of the function that called fn1 , etc. |
import callerDirname from 'caller-dirname';
export const thirdCallerDir = () => callerDirname({ depth: 3 });
I needed this for another repo I'm working on. Most of the code is taken from caller-path. The main difference is this returns the dirname only, rather than the full path with filename and extension. Also, it's published both as a CommonJS module and as an ES Module and includes TypeScript typings.
FAQs
Get the directory name of a caller function's containing file.
We found that caller-dirname demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.