color-prefix-stream
Add a color and a prefix to each line in a streamInstall
To installcolor-prefix-stream
, simply use npm:npm install color-prefix stream --save
Example
The example below can be found hereexample and ran usingnode example.js
. It uses color-prefix-stream
to print multiple lines using random-picked colors.'use strict'
const prefixer = require('.')
const instances = [
prefixer({ prefix: 'i1', rotate: true }),
prefixer({ prefix: 'i2', rotate: true }),
prefixer({ prefix: 'i3', rotate: true })
]
instances.forEach((i) => i.pipe(process.stdout, { end: false }))
function print () {
instances.forEach((i) => i.write(Math.random() + '\n'))
setTimeout(print, 1000)
}
print()
API
prefixer(opts)
Returns a split2split2 stream configure to add a prefix and a color to each line.Options:
prefix
: the prefix to prepend.separator
: to be used between the prefix and the line, defaults to:
.color
: the chalkchalk color to use.rotate
: rotate between a set of colors, with global state. Defaults
false
.eol
: the end of line to use to reconstruct the lines. Defaults to
require('os').EOL
.