Function getCallerPath

  • Attempts to get the path to the file that contains the code that called the code that called this function. I know, it's confusing, but it's cool.

    Returns string | undefined

    // /path/to/file.ts
    import { foo } from './path/to/foo.ts';

    foo();
    // /path/to/foo.ts
    import { getCallerPath } from 'src/utils/get-caller';

    export function foo() {
    console.log(getCallerPath()); // /path/to/file.ts
    }