as-procedure
Version:
easily create procedures within a pit-of-success
27 lines • 935 B
JavaScript
;
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();
}
catch {
return undefined;
}
finally {
Error.prepareStackTrace = originalPrepareStackTrace;
}
};
exports.getCallerFileName = getCallerFileName;
//# sourceMappingURL=getCallerFileName.js.map