Needle-Pinpointing Machine

color-prefix-stream

1.0.0 • Public • Published

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 here 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 split2 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 chalk 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.

install

npm i color-prefix-stream

Downloadsweekly downloads

5

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability