@stacktrace-lite/core
    Preparing search index...

    Function formatStack

    • Format an array of StackFrame entries into a string based on the desired output mode.

      Parameters

      • frames: StackFrame[]

        Parsed stack frames to format.

      • mode: FormatMode = 'cli'

        Output style:

        • "cli" – styled for terminal (default)
        • "html" – safe for rendering into web UIs
        • "json" – structured JSON
        • "raw" – concatenated original lines (frame.raw)

      Returns string

      A formatted string representing the stack trace.

      Terminal styling ("cli") Uses the colorette library to render ANSI styling:

      • bold(...) for function names
      • dim('at') for the “at” constant
      • yellow(...) for file names
      • gray(...) for line/column position Colorette is chosen for its speed and zero dependencies—efficient and NO_COLOR friendly.:contentReference[oaicite:1]{index=1}

      HTML mode ("html") Safely escapes HTML entities and assembles a <pre> block with semantic <span> tags (function, at, file, pos)—great for embedding in browser error overlays or dev UI.

      JSON mode ("json") Outputs the full frames array as pretty JSON (null, 2 spacing), ideal for logging or backend ingestion.

      Raw mode ("raw") Joins the raw values of frames, preserving their original formatting without transformation.

      const trace = formatStack(frames, 'cli');
      console.log(trace);

      const htmlTrace = formatStack(frames, 'html');
      document.body.innerHTML = htmlTrace;

      const jsonTrace = formatStack(frames, 'json');
      sendToServer(jsonTrace);

      Error when an unsupported mode string is provided.