Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

caller-dirname

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caller-dirname

Get the directory name of a caller function's containing file.

  • 1.0.0
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

caller-dirname

Get the directory name of a caller function's containing file.


Installation

$ npm i caller-dirname

Usage

/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 */

Options

OptionDefaultDescription
depth1Depth 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.
Example
import callerDirname from 'caller-dirname';

export const thirdCallerDir = () => callerDirname({ depth: 3 });

Motivation

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

Package last updated on 19 Apr 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc