Streaming interface to node-wordwrap
const fs =const wordwrap =const file = fsconst wrap =file
npm install -g wordwrap-stream; all of the following examples are
$ wordwrap --stop 20 file.txt > wrapped.txt $ wordwrap 20 file.txt > wrapped.txt $ cat file.txt | wordwrap --stop 20 > wrapped.txt
wordwrap --help for a full lits of options.
wordwrap(wrapOpts, [streamOpts]) -> transformStream
wrapOpts(object) an options object, with the following keys; these options are passed through to the wordwrap instance, so check those docs for details on each:
stop(integer) the column at which text should be wrapped
start(optional, integer, default:
0) the offset at which to pad out lines
mode(optional, string, default:
soft) if words that are longer than
stop - startshould be forcibly split
lengthFn(optional, function, default:
String.length) a function that should be used to determine the length of the current chunk; by default it just uses the string's
.lengthproperty, but should you choose you can pass a function that understands other lengths (like double-width characters, for instance)
streamOpts(optional, object) options passed to the underlying transformStream; this is where you could specify the streams
highWaterMarkor put it into
objectMode. Read the stream docs for details.
wordwrap-streamonly deals with chunks of data as it gets them, it needs to remember the last line to ensure that there isn't a "break" where a line is too short. It's important to end the stream (or its data source), which will flush the stream.
MIT. See LICENSE for details.