Gathering detailed insights and metrics for node-ansiparser
Gathering detailed insights and metrics for node-ansiparser
Gathering detailed insights and metrics for node-ansiparser
Gathering detailed insights and metrics for node-ansiparser
ANSI escape sequence parser for node.js and the browser.
npm install node-ansiparser
Typescript
Module System
Node Version
NPM Version
JavaScript (98.52%)
HTML (1.48%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
23 Stars
18 Commits
2 Forks
6 Watchers
2 Branches
1 Contributors
Updated on Dec 05, 2024
Latest Version
2.2.1
Package Id
node-ansiparser@2.2.1
Unpacked Size
171.97 kB
Size
34.88 kB
File Count
18
NPM Version
6.14.13
Node Version
14.17.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A parser for ANSI escape code sequences. It implements the parser described here http://vt100.net/emu/dec_ansi_parser (thanks to Paul Williams).
NOTE ON UNICODE: The parser works with unicode strings. High characters (any above 0x9f) are only allowed within the string consuming states GROUND (for print), OSC_STRING and DCS_PASSTHROUGH. At any other state they will either be ignored (CSI_IGNORE and DCS_IGNORE) or cancel the active escape sequence. Although this doesn't follow any official specification (since I haven't found any) it seems to work with unicode terminal streams.
The parser uses callbacks to methods of a given terminal object. Methods a terminal should implement:
NOTE ON CALLBACK INVOCATIONS All callbacks will be triggered as soon as the escape sequence is finished.
The callbacks inst_o
, inst_x
, inst_c
, inst_e
, inst_H
and
int_U
are guaranteed to be finished. If a corresponding escape sequence is not
finished at the end of the parse input the parser will not trigger the callback until the
sequence gets finished by later .parse
calls.
inst_p
and inst_P
are not guaranteed to be finished. They can occur multiple times in a row
and they will always be triggered at the end of the parse input:
inst_p
- Since Javascript uses a variable multibyte encoding for high unicode characters
there is a small chance that the last character is part of a multibyte character
and not directly printable, e.g. parse('<high byte>'); parse('<low byte>');
. To handle
it you will have to track this edge case in your terminal object.
inst_P
- is part of the DCS subsystem and likely to contain arbitrary length data.
To handle this with the correct DCS subparser the terminal object has to respect
the dcs_hook via inst_H
until dcs_unhook inst_U
is called.
Although the OSC subsystem is intended to work similar to the DCS subsystem the parser does not expose the osc_start, osc_end and osc_put calls. The OSC use cases are well defined and the data part is likely to be very short. Therefore the parser summarizes the OSC actions to only one final OSC callback. OSC parsing itself is not covered by this parser.
There is an optional inst_E(e)
callback to track parsing errors with e
containing all internal
parser states at error time. By returning a similar object from this callback
you can inject new values to the parsing process or abort it with {abort:true}
.
The parser will fall to state 'GROUND' and continue with the next character
if you don't return anything (default behavior).
NOTE: If the terminal object doesn't provide the needed methods the parser will inject dummy methods to keep working.
This example uses a simple terminal object, which just logs the actions:
1var AnsiParser = require('node-ansiparser'); 2 3var terminal = { 4 inst_p: function(s) {console.log('print', s);}, 5 inst_o: function(s) {console.log('osc', s);}, 6 inst_x: function(flag) {console.log('execute', flag.charCodeAt(0));}, 7 inst_c: function(collected, params, flag) {console.log('csi', collected, params, flag);}, 8 inst_e: function(collected, flag) {console.log('esc', collected, flag);}, 9 inst_H: function(collected, params, flag) {console.log('dcs-Hook', collected, params, flag);}, 10 inst_P: function(dcs) {console.log('dcs-Put', dcs);}, 11 inst_U: function() {console.log('dcs-Unhook');} 12}; 13 14 15var parser = new AnsiParser(terminal); 16parser.parse('\x1b[31mHello World!\n'); 17parser.parse('\x1bP0!u%5\x1b\'');
For a more complex terminal see node-ansiterminal.
The parser has a throughput of 50 - 100 MB/s with my desktop computer.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/17 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More