Socket
Socket
Sign inDemoInstall

caller-dirname

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    caller-dirname

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


Version published
Weekly downloads
3.8K
decreased by-1.58%
Maintainers
1
Install size
8.09 kB
Created
Weekly downloads
 

Readme

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

Last updated on 20 Apr 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc