UNPKG

as-procedure

Version:

easily create procedures within a pit-of-success

27 lines 948 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCallerFileName = void 0; /** * .what = procedure to get the file.name that this function was called from */ const getCallerFileName = (input = { depth: 2 }) => { const originalPrepareStackTrace = Error.prepareStackTrace; try { Error.prepareStackTrace = (_, stack) => stack; const err = new Error(); const stack = err.stack; // depth = 0 is this function // depth = 1 is the function that called this function // depth = 2 is the caller of the function that called this function const callSite = stack[input.depth]; return callSite?.getFileName() ?? undefined; } catch { return undefined; } finally { Error.prepareStackTrace = originalPrepareStackTrace; } }; exports.getCallerFileName = getCallerFileName; //# sourceMappingURL=getCallerFileName.js.map