{"version":3,"sources":["../src/capLength.ts","../src/toReadableString.ts"],"sourcesContent":["import { toReadableString } from \"./toReadableString\";\n\nexport function capLength(u: unknown, maxLength = 400): string {\n  const s = toReadableString(u);\n\n  if (s.length <= maxLength) {\n    return s;\n  }\n\n  return s.slice(0, maxLength) + ` ... (${s.length - maxLength} more)`;\n}\n","/**\n * Make the given argument of unknown type into something human-readable.\n * For Error objects, you can specify options to make the string more verbose.\n */\nexport function toReadableString(\n  u: unknown,\n  options?: { includeStack?: boolean; includeErrorProps?: boolean },\n): string {\n  if (typeof u === \"string\") {\n    return u;\n  }\n\n  if (u === undefined) {\n    return \"undefined\";\n  }\n\n  if (u instanceof Error) {\n    const error = u as Error;\n    let result = \"\";\n\n    // Always include the name and message\n    const errorName = error.name || \"Error\";\n    const errorMessage =\n      error.message || \"An error occurred with no message provided.\";\n\n    result += `${errorName}: ${errorMessage}`;\n\n    // Optionally include the stack trace\n    if (options?.includeStack && error.stack) {\n      // Clean up the stack trace to start on a new line,\n      // removing potential duplicate header lines if the browser adds them.\n      const stack = error.stack\n        // Remove the first line if it duplicates the name/message\n        .replace(new RegExp(`^${errorName}:.*\\\\n?`), \"\")\n        .trim();\n\n      if (stack) {\n        result += `\\nStack Trace:\\n${stack}`;\n      }\n    }\n\n    // Add any potential custom error properties (e.g., HTTP status code)\n    if (options?.includeErrorProps) {\n      // eslint-disable-next-line @typescript-eslint/no-explicit-any\n      const customProps: { [key: string]: unknown } = error as any;\n\n      const additionalInfo = Object.keys(customProps)\n        .filter(\n          (key) =>\n            key !== \"name\" &&\n            key !== \"message\" &&\n            key !== \"stack\" &&\n            typeof customProps[key] !== \"function\" &&\n            typeof customProps[key] !== \"object\",\n        )\n        .map((key) => `\\n- ${key}: ${customProps[key]}`);\n\n      if (additionalInfo.length > 0) {\n        result += `\\nAdditional Data:${additionalInfo.join(\"\")}`;\n      }\n    }\n\n    return result;\n  }\n\n  // If the object has a custom toString(), then use it.\n  if (u && typeof u === \"object\" && u.toString !== Object.prototype.toString) {\n    return u.toString();\n  }\n\n  try {\n    // Attempt to JSON stringify the object for inspection.\n    return JSON.stringify(u);\n  } catch {\n    // Fallback if the object cannot be stringified (e.g., circular references).\n    return String(u);\n  }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,IAAA,eAAAC,EAAAH,GCIO,SAASI,EACdC,EACAC,EACQ,CACR,GAAI,OAAOD,GAAM,SACf,OAAOA,EAGT,GAAIA,IAAM,OACR,MAAO,YAGT,GAAIA,aAAa,MAAO,CACtB,IAAME,EAAQF,EACVG,EAAS,GAGPC,EAAYF,EAAM,MAAQ,QAC1BG,EACJH,EAAM,SAAW,8CAKnB,GAHAC,GAAU,GAAGC,CAAS,KAAKC,CAAY,GAGnCJ,GAAS,cAAgBC,EAAM,MAAO,CAGxC,IAAMI,EAAQJ,EAAM,MAEjB,QAAQ,IAAI,OAAO,IAAIE,CAAS,SAAS,EAAG,EAAE,EAC9C,KAAK,EAEJE,IACFH,GAAU;AAAA;AAAA,EAAmBG,CAAK,GAEtC,CAGA,GAAIL,GAAS,kBAAmB,CAE9B,IAAMM,EAA0CL,EAE1CM,EAAiB,OAAO,KAAKD,CAAW,EAC3C,OACEE,GACCA,IAAQ,QACRA,IAAQ,WACRA,IAAQ,SACR,OAAOF,EAAYE,CAAG,GAAM,YAC5B,OAAOF,EAAYE,CAAG,GAAM,QAChC,EACC,IAAKA,GAAQ;AAAA,IAAOA,CAAG,KAAKF,EAAYE,CAAG,CAAC,EAAE,EAE7CD,EAAe,OAAS,IAC1BL,GAAU;AAAA,kBAAqBK,EAAe,KAAK,EAAE,CAAC,GAE1D,CAEA,OAAOL,CACT,CAGA,GAAIH,GAAK,OAAOA,GAAM,UAAYA,EAAE,WAAa,OAAO,UAAU,SAChE,OAAOA,EAAE,SAAS,EAGpB,GAAI,CAEF,OAAO,KAAK,UAAUA,CAAC,CACzB,MAAQ,CAEN,OAAO,OAAOA,CAAC,CACjB,CACF,CD3EO,SAASU,EAAUC,EAAYC,EAAY,IAAa,CAC7D,IAAMC,EAAIC,EAAiBH,CAAC,EAE5B,OAAIE,EAAE,QAAUD,EACPC,EAGFA,EAAE,MAAM,EAAGD,CAAS,EAAI,SAASC,EAAE,OAASD,CAAS,QAC9D","names":["capLength_exports","__export","capLength","__toCommonJS","toReadableString","u","options","error","result","errorName","errorMessage","stack","customProps","additionalInfo","key","capLength","u","maxLength","s","toReadableString"]}