2.0.0 • Published 2 years ago

output-buffer v2.0.0

Weekly downloads
13
License
Apache-2.0 OR MIT
Repository
github
Last release
2 years ago

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.

2.0.0

2 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago