New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sgr-parser

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sgr-parser

Parse escape sequence for console. (Especially for SGR)

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
51
increased by363.64%
Maintainers
1
Weekly downloads
 
Created
Source

sgr-parser

Parse console output which includes escape sequence.

Install

npm install sgr-parser

How to use

SGRParser takes two constructor parameters.

  • keepState: Keep previous state while continuous parsing.
  • handleCR : Deal CR(0x0d) code as ESC[2K(Remove current line.)

SGRParser has following two methods.

  • tokenize(str: string): Array;
    • It returns 3 kind of Token(StringToken, EscapeToken, ErrorToken)
    • StringToken has str property. It holds tokenized string.
    • EscapeToken has options property and code property. options is array of number. code is code of key.
    • ErrorToken means invalid EscapeSequence. It is almost same as StringToken.
  • parse(str)
    • It returns Array of Line object.
    • Line object has following four properties.
    • str: string
    • classname: It holds sgr classname. (e.g. sgr-33-m)
    • newLine: true means LF exists before this string.
    • removeLine: If the escape sequence ESC[2K exists, it will be Line("", "", false, true).
    • Other escapes except ESC[[n]m will be ignored.
var SGRParser = require("sgr-parser");

var input = "\u001b[31mtest\u001b[0m";
var lines = new SGRParser(true, true).parse(input); // [Line("test", "sgr-31-m", false, false)]

Keywords

FAQs

Package last updated on 09 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc