A parser for ANSI escape code sequences implementing the state machine described at vt100.net/emu/dec_ansi_parser. Version 2.2.1 is the latest stable release, with no further updates expected. It provides callbacks for printable characters, OSC, execute, CSI, ESC, and DCS sequences. Unlike alternatives (e.g., ansi-parser), this library follows the DEC ANSI parser specification closely, supports unicode, and allows injection of error handling. It is designed for Node.js and requires only a terminal object with specific callback methods.
npm install node-ansiparserVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic ANSI escape sequence parsing with a terminal object that logs all callbacks.
Ensure unicode input is cleanly split; avoid sending partial multibyte characters across parse calls.
Buffer partial characters manually; the parser does not reassemble multibyte sequences across calls.
Use import AnsiParser from 'node-ansiparser' instead of require.
Always implement all callbacks (inst_p, inst_o, inst_x, inst_c, inst_e, inst_H, inst_P, inst_U) to avoid unexpected behavior.
Return { abort: true } from inst_E to abort parsing on error.Add an inst_x method to your terminal object: inst_x(flag) { console.log('execute', flag.charCodeAt(0)); }Use import statement: import AnsiParser from 'node-ansiparser'
Ensure you have installed the package and use correct import: 'node-ansiparser'.
No dependency data recorded yet.