npm

output-buffer
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

output-buffer

codecov CI

Buffers your outputs and calls a function when a linebreak is found

Table of contents

Install

$ npm i output-buffer

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

Usage

import { OutputBuffer } from 'output-buffer'

const 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.:

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

or:

const 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.

const 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

License

Licensed under either of

Contribute

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Readme

Keywords

Package Sidebar

Install

npm i output-buffer

Weekly Downloads

8

Version

2.0.0

License

Apache-2.0 OR MIT

Unpacked Size

14.1 kB

Total Files

8

Last publish

Collaborators

  • achingbrain