Anser is a low-level parser for ANSI escape codes, converting terminal text with color/style sequences into HTML elements, JSON, or plain text. Version 2.3.5 is the current stable release, with infrequent updates focused on bug fixes and edge cases. Key differentiators: supports true color (24-bit), 256-color palette, and SGR parameters; provides both HTML and JSON output; includes link detection and HTML escaping; has TypeScript definitions. Alternatives like chalk focus on terminal output, not parsing, while ansi-to-html is less feature-rich. Released under MIT license.
npm install anserVerified import paths — ran on the pinned version, not inferred.
Demonstrates converting ANSI-colored text to HTML with inline styles, CSS classes, JSON, and plain text removal.
Use import syntax or set type: 'module' in package.json. For CommonJS, use dynamic import or await import('anser').Access json object properties directly without relying on isEmpty function. Use content, fg, bg, etc.
Enable esModuleInterop in tsconfig.json, or use import Anser = require('anser') and use as namespace.Customize class names by mapping the palette yourself, or use inline styles (default).
Pre-process text with a linkify library before passing to anser.
Update to v2.3.5+ which fixes grayscale palette returning undefined.
npm install anser (types included) or yarn add anser. No separate @types needed.
Use import Anser from 'anser' (ESM) or const Anser = require('anser').default (CommonJS).Use import Anser from 'anser' and call Anser.ansiToHtml, or enable esModuleInterop.
Add "type": "module" to package.json or rename file to .mjs.
No dependency data recorded yet.