{"library":"stacktracey","title":"StackTracey: Stack Trace Parser & Pretty Printer","type":"library","description":"StackTracey is a robust JavaScript library designed for parsing call stacks, reading source code, and generating clean, filtered, and pretty-printed output. Currently at version 2.2.0, it targets both Node.js and browser environments, supporting cross-platform compatibility across various operating systems like Windows and *nix. The library differentiates itself with full sourcemap support, the ability to fetch source text for call locations (leveraging `get-source`), and mechanisms for ad-hoc exclusion of irrelevant stack frames (e.g., library calls or user-defined exclusions via `// @hide` markers). It provides both synchronous and asynchronous interfaces for accessing source code, with asynchronous being the preferred method for browser environments to avoid blocking the main thread. It also extracts useful information from `SyntaxError` instances, making it valuable for debugging and enhanced error reporting in development tools and logging solutions.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install stacktracey"],"cli":null},"imports":["import StackTracey from 'stacktracey'","import type { StackTraceyItem } from 'stacktracey'","const stackWithSources = await new StackTracey(error).withSourcesAsync()"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://xpl.github.io/stacktracey","github":"https://github.com/xpl/stacktracey","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/stacktracey","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import StackTracey from 'stacktracey';\n\nasync function demonstrateStackTracey() {\n  try {\n    // Simulate an error to capture its stack\n    const divideByZero = () => { throw new Error('Cannot divide by zero!'); };\n    divideByZero();\n  } catch (error) {\n    console.log('--- Original Error Stack ---');\n    console.error(error.stack);\n\n    // Create a StackTracey instance from the error\n    let stack = new StackTracey(error);\n    console.log('\\n--- Parsed StackTracey Items (first 2) ---');\n    stack.items.slice(0, 2).forEach((item, index) => {\n      console.log(`Item ${index}:`, {\n        callee: item.callee,\n        fileRelative: item.fileRelative,\n        line: item.line,\n        column: item.column,\n        thirdParty: item.thirdParty\n      });\n    });\n\n    // Fetch sources asynchronously (recommended for browsers and Node for non-blocking I/O)\n    console.log('\\n--- Fetching sources asynchronously ---');\n    const stackWithSources = await stack.withSourcesAsync();\n    const topItem = stackWithSources.items[0];\n    if (topItem.sourceFile) {\n      console.log(`\\nSource for top frame (${topItem.fileShort}:${topItem.line}):`);\n      console.log(topItem.sourceFile.text.split('\\n')[topItem.line - 1].trim());\n    } else {\n      console.log('Source not available for the top frame.');\n    }\n\n    // Pretty print the stack\n    console.log('\\n--- Pretty-printed StackTracey ---');\n    console.log(stackWithSources.pretty);\n  }\n}\n\ndemonstrateStackTracey().catch(console.error);\n","lang":"typescript","description":"This quickstart demonstrates how to capture and parse an error stack, access individual stack frame properties, asynchronously fetch source code for frames, and finally pretty-print the entire processed stack. It highlights the library's core capabilities for error introspection and rich output.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}