color-prefix-stream

Add a color and a prefix to each line in a stream

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
color-prefix-stream
101.0.08 years ago8 years agoMinified + gzip package size for color-prefix-stream in KB

Readme

color-prefix-stream
Add a color and a prefix to each line in a stream

Install

To install color-prefix-stream, simply use npm:
npm install color-prefix stream --save

Example

The example below can be found hereexample and ran using node 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
to false.
  • eol: the end of line to use to reconstruct the lines. Defaults to
require('os').EOL.

Acknowledgements

This project was kindly sponsored by nearForm.

License

Copyright Matteo Collina 2016, Licensed under MIT.