caller-path

  • Version 3.0.1
  • Published
  • 5.04 kB
  • 1 dependency
  • MIT license

Install

npm i caller-path
yarn add caller-path
pnpm add caller-path

Overview

Get the path of the caller function

Index

Functions

Interfaces

Functions

function callerPath

callerPath: (options?: callerPath.Options) => string | undefined;
  • Get the path of the caller function.

    If the caller's [callsite](https://github.com/sindresorhus/callsites#api) object getFileName was not defined for some reason, it will return undefined.

    Example 1

    // foo.ts
    import callerPath = require('caller-path');
    export default () => {
    console.log(callerPath());
    //=> '/Users/sindresorhus/dev/unicorn/bar.ts'
    }
    // bar.ts
    import foo from './foo';
    foo();

Interfaces

interface Options

interface Options {}

    property depth

    readonly depth?: number;
    • The caller path depth, meaning how many levels we follow back on the stack trace.

      0

      Example 1

      ``` // foo.ts import callerPath = require('caller-path');

      module.exports = () => { console.log(callerPath()); //=> '/Users/sindresorhus/dev/unicorn/foobar.ts' console.log(callerPath({depth: 1})); //=> '/Users/sindresorhus/dev/unicorn/bar.ts' console.log(callerPath({depth: 2})); //=> '/Users/sindresorhus/dev/unicorn/foo.ts' }

      // bar.ts import foo = require('./foo');

      module.exports = () => { foo(); }

      // foobar.ts import bar = require('./bar'); bar(); ```

    Package Files (1)

    Dependencies (1)

    Dev Dependencies (3)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/caller-path.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/caller-path)
    • HTML
      <a href="https://www.jsdocs.io/package/caller-path"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>