Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
caller-dirname
Advanced tools
Readme
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.
The npm package caller-dirname receives a total of 3,781 weekly downloads. As such, caller-dirname popularity was classified as popular.
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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.