each-part
Transform stream which emits each part and pushes object with part.
Uses newline and carriage return for default delimiter (one or both in either order).
Install
npm install each-part --save
Usage
buildEach = require 'each-part' # uses newline or carriage return by default # outputs `part` object by default, which contains `string` and `delim` eachLine = buildEach eachLineon 'part' # do something with the part. # when readableObjectMode is true, the default, then `part` is an object # with two properties: `string` and `delim` # when it's not true (you specify it as false in options) then `part` is the # string. The second arg is always `delim` eachLineon 'error' # do something with the error... eachLineon 'finish' # all done... # part is also passed on as an object to the next stream using objectMode:true targetStream = require'through2' # do something with the part: part.string consolelog 'part:'partstring next someStreampipeeachLine # can provide options to override the delimiter used: eachPipe = buildEach delim:'|' # can be a regular expression: eachBlah = buildEach delim:/blah/ # to pass `string` to the next stream, set readableObjectMode to false: eachLine = buildEach readableObjectMode:false# when you do that, then: # 1. the stream it pipes to will receive strings as chunks # 2. the 'part' event will provide the string as the first arg, not an object # Note: this means the next stream will not know the delimiter found