Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tilfin/readline-transform
Transform stream to read content line-by-line and write a string
https://github.com/tilfin/readline-transform
byline nodejs npm readline stream transform
Last synced: 16 days ago
JSON representation
Transform stream to read content line-by-line and write a string
- Host: GitHub
- URL: https://github.com/tilfin/readline-transform
- Owner: tilfin
- License: mit
- Created: 2017-11-29T10:45:18.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-31T03:02:40.000Z (about 4 years ago)
- Last Synced: 2024-10-02T07:16:50.696Z (about 1 month ago)
- Topics: byline, nodejs, npm, readline, stream, transform
- Language: JavaScript
- Size: 23.4 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ReadlineTransform
[![npm](https://img.shields.io/npm/v/readline-transform.svg)](https://www.npmjs.com/package/readline-transform)
[![Node](https://img.shields.io/node/v/readline-transform.svg)]()
[![License](https://img.shields.io/github/license/tilfin/readline-transform.svg)]()
[![dependencies Status](https://david-dm.org/tilfin/readline-transform/status.svg)](https://david-dm.org/tilfin/readline-transform)
[![Build Status](https://travis-ci.org/tilfin/readline-transform.svg?branch=master)](https://travis-ci.org/tilfin/readline-transform)
[![Coverage Status](https://coveralls.io/repos/github/tilfin/readline-transform/badge.svg?branch=master)](https://coveralls.io/github/tilfin/readline-transform?branch=master)Reading String or Buffer content from a Readable stream and writing each line which ends without line break as object
## Install
```
$ npm install -save readline-transform
```## How to Use
### Create a ReadlineTransform
**new ReadlineTransform(options)**
* `options` ``
* `breakMatcher` is the regular expression to split content by line break for `str.split()`. (default: `/\r?\n/`)
* `ignoreEndOfBreak` is boolean. if content ends with line break, ignore last empty line. (default: `true`)
* `skipEmpty` is boolean. if line is empty string, skip it (default: `false`)### An example
```javascript
const { PassThrough } = require('stream');
const ReadlineTransform = require('readline-transform');const readStream = new PassThrough();
const transform = new ReadlineTransform({ skipEmpty: true });
const writeStream = new PassThrough({ objectMode: true });writeStream.on('data', (line) => {
console.log(line);
}).on('finish', () => {
console.log('<<< all done >>>');
});readStream.pipe(transform).pipe(writeStream);
readStream.write(new Buffer('foo\nba'));
readStream.write(new Buffer('r\r\n\n\r'));
readStream.end(new Buffer('\nbaz'));
```### Console output
```
$ node example.js
foo
bar
baz
<<< all done >>>
```