@mnrendra/stack-trace
Version:
A lightweight stack trace utility to retrieve CallSite objects from a specific caller.
3 lines (2 loc) • 883 B
JavaScript
;var T=require("node:url"),s=require("node:path");const m=()=>({stack:[]}),E=r=>{if(typeof r!="string")throw new Error(`Caller's file name is not a string: \`${r}\``);try{return T.fileURLToPath(r)}catch{return r}},a=(r,{limit:t=1/0}={})=>{const{stackTraceLimit:e,prepareStackTrace:u}=Error;Error.stackTraceLimit=t,Error.prepareStackTrace=(h,p)=>p;const n=m();Error.captureStackTrace(n,r??a);const{stack:k}=n;return Error.prepareStackTrace=u,Error.stackTraceLimit=e,k},c=r=>{const[t]=a(r??c,{limit:1});return t},i=r=>{const t=r.getFileName(),e=E(t);if(!s.isAbsolute(e))throw new Error(`Caller's file path is not absolute: "${e}"`);return e},o=r=>{const t=c(r??o);return i(t)},l=r=>{const t=o(r??l);return s.dirname(t)};exports.extractFilePath=i,exports.getCallerDir=l,exports.getCallerFile=o,exports.getCallerSite=c,exports.stackTrace=a;
//# sourceMappingURL=index.js.map