1.1.0 • Published 8 years ago

stream-insert v1.1.0

Weekly downloads
132
License
MIT
Repository
github
Last release
8 years ago

stream-insert

npm Build Status Coverage Status dependencies Status devDependencies Status

Transform stream which insert text into the passing stream

Usage

stream-insert implements the Tranform Stream API.

var fs = require('fs');

var StreamInsert = require('stream-insert');

var insert = new StreamInsert('Line to append', /^Searched line$/);

fs.createReadStream('input.txt').pipe(insert).pipe(fs.createWriteStream('output.txt'));

API

StreamInsert(insertions, query, options)
Parameters
ParameterType(s)RequiredDefaultDescription
insertionsstring, string[]YesStrings to insert into the stream.
queryobject, string, string[], RegExp, RegExp[]YesQuery object (see below) or RegExp(s)/string(s) used to detect where the strings will be inserted.
optionsobject, stringNo{}Additional options. If a string is passed, set the separator option.
Query
FilterType(s)RequiredDefaultDescription
searchesstring, string[], RegExp, RegExp[]YesRegExp(s)/string(s) used to detect where the strings will be inserted.
operatorstringNoANDIf AND, insert after all searches are found (sequentially). If OR, insert after each matching search.
beforeRegExp, stringNonullDon't insert after this RegExp matched.
afterRegExp, stringNonullDon't insert until this RegExp matched.
strictbooleanNotrueIn strict mode, boudaries (before & after) are not tested against searches.
Options
OptionType(s)RequiredDefaultDescription
prependbooleanNofalseInsert strings before the last match, after otherwise.
separatorstringNo\nSeparator used to split the stream. Default to \n to read the input stream line by line.
limitnumberNo-1Maximum number of insertions (-1 for infinity).
insertSeparatorbooleanNotrueIf true, insert the separator between the insert and the matched string.

Examples