UNPKG

@fajarnugraha37/error

Version:

Runtime-agnostic error handling library with structured errors, adapters, and validation support for Bun, Node.js, and browsers

6 lines (5 loc) 1.68 kB
"use strict";var u=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var o=(e,n)=>u(e,"name",{value:n,configurable:!0});var d=(e,n)=>{for(var t in n)u(e,t,{get:n[t],enumerable:!0})},y=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of p(n))!f.call(e,r)&&r!==t&&u(e,r,{get:()=>n[r],enumerable:!(i=c(n,r))||i.enumerable});return e};var g=e=>y(u({},"__esModule",{value:!0}),e);var M={};d(M,{normalizeStack:()=>h,truncateStack:()=>_});module.exports=g(M);var b=[/at Object\.<anonymous>/,/at Module\._compile/,/at Module\.load/,/at Function\.Module\._load/,/at Module\.require/,/at require \(node:internal/,/node_modules/,/@fajarnugraha37\/error\/dist/];function T(){return typeof globalThis<"u"&&"Bun"in globalThis?{type:"bun",version:globalThis.Bun?.version}:typeof process<"u"&&process.versions?.node?{type:"node",version:process.versions.node}:typeof window<"u"?{type:"browser"}:{type:"unknown"}}o(T,"detectRuntime");function h(e){let n=T(),t=e.replace(/\r\n/g,` `),i=t.split(` `),r=[],a=0;for(let s of i){if(!s.trim().startsWith("at ")){r.push(s);continue}if(!b.some(l=>l.test(s))){if(a>=50){r.push(" ... (truncated)");break}r.push(s),a++}}return t=r.join(` `),(n.type==="browser"||n.type==="bun")&&(t=m(t)),t}o(h,"normalizeStack");function m(e){if(typeof globalThis<"u"&&"__stackTraceMapper"in globalThis)try{let n=globalThis.__stackTraceMapper;if(typeof n=="function")return n(e)||e}catch{}return e}o(m,"applySourceMaps");function _(e,n=1e3){return e.length<=n?e:e.slice(0,n)+` ... (truncated)`}o(_,"truncateStack");0&&(module.exports={normalizeStack,truncateStack});