Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

output-buffer

1.2.0 • Public • Published

OutputBuffer

Build Status Dependency Status Coverage Status

Buffers your output. When line separators are detected, it calls the function passed to the constructor with the line of data.

Usage

var OutputBuffer = require('output-buffer')
 
var buffer = new OutputBuffer(console.info)
buffer.append('foo')
buffer.append('bar')
buffer.append('\n')  // prints 'foobar'
buffer.append('foo')
buffer.append('ba\nr') // prints fooba
buffer.flush() // prints 'r'

Specifying a line separator

The default line separator is the regex /\r\n|\r|\n/ - this will handle CRLF, CR or LF.

A custom separator (string or regex) can be supplied as a second argument to the constructor, e.g.:

var buffer = new OutputBuffer(console.info, '\r\n')

or:

var buffer = new OutputBuffer(console.info, /\r\n/)

Finding the size of the buffer

buffer.size() will return how many characters have yet to be passed to the callback.

var buffer = new OutputBuffer(console.info, '\r\n')
 
console.info(buffer.size()) // prints 0
 
buffer.append('foo')
 
console.info(buffer.size()) // prints 3
 
buffer.append('bar/n')
 
console.info(buffer.size()) // prints 0

Keywords

install

npm i output-buffer

Downloadsweekly downloads

183

version

1.2.0

license

BSD

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability