wordwrap-stream
v1.1.0
Published
Streaming interface to node-wordwrap
Downloads
7
Readme
wordwrap-stream
Streaming interface to node-wordwrap
Example
const fs = require('fs')
const wordwrap = require('wordwrap-stream')
const file = fs.createReadStream('somefile.txt')
const wrap = wordwrap({stop: 20})
file.pipe(wrap)
CLI
Install with npm install -g wordwrap-stream
; all of the following examples are
equivalent:
$ wordwrap --stop 20 file.txt > wrapped.txt
$ wordwrap 20 file.txt > wrapped.txt
$ cat file.txt | wordwrap --stop 20 > wrapped.txt
Use wordwrap --help
for a full lits of options.
API
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 wrappedstart
(optional, integer, default:0
) the offset at which to pad out linesmode
(optional, string, default:soft
) if words that are longer thanstop - start
should be forcibly splitlengthFn
(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.length
property, 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 streamshighWaterMark
or put it intoobjectMode
. Read the stream docs for details.
Notes
- Because
wordwrap-stream
only 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.
License
MIT. See LICENSE for details.