You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

ansi-stream

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansi-stream

Converts a text stream to a stream of strings and `EscapeCode` objects

0.0.1
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

ansi-stream

Converts a text stream to a stream of strings and EscapeCode objects

Build Status Coverage Status Code Climate Dependency Status devDependency Status

NPM

Usage

  var ansiStream = require('ansi-stream');
  var EscapeCode = ansiStream.EscapeCode;
  
  stream = ansiStream();
  stream.write('\x1b[31mabc\x1b[39m');
  stream.end();
  
  assert.deepEqual(
    stream.read(),
    new EscapeCode('\x1b[31m')
  );
  
  assert.strictEqual(
    stream.read(),
    'abc'
  );
  
  assert.deepEqual(
    stream.read(),
    new EscapeCode('\x1b[39m')
  );

API

ansiStream(maxBuffer)

Creates a new stream instance, with an optional buffer size.

maxBuffer

Optional
Type: number

Handles the (rare) case where an escape code sequence might span two chunks.

If it does not detect a complete escape code in the chunk, but there is a control character (\u001b, or \u009b), it will buffer up to maxBuffer characters until the next chunk.

If you are sure that your input will NOT split escape code sequences across chunks, you can set this to zero for improved performance.

ansiStream.EscapeCode

Can be used by streams further down the chain to discover if a given chunk is an EscapeCode or not. See escape-code for more details.

  stream.on('data', function(chunk) {
    if (chunk instanceof ansiStream.EscapeCode) {
      // process the escape code
    } else {
      // process a chunk of plain old text.
    }
  });

License

MIT © James Talmage

FAQs

Package last updated on 21 Jul 2015

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