Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/color-prefix-stream
Add a color and a prefix to each line in a stream
https://github.com/mcollina/color-prefix-stream
Last synced: 13 days ago
JSON representation
Add a color and a prefix to each line in a stream
- Host: GitHub
- URL: https://github.com/mcollina/color-prefix-stream
- Owner: mcollina
- License: mit
- Created: 2016-07-08T20:21:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-07-09T00:30:39.000Z (over 8 years ago)
- Last Synced: 2024-12-17T15:42:29.875Z (23 days ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# color-prefix-stream
Add a color and a prefix to each line in a stream
* [Install](#install)
* [Example](#example)
* [API](#api)
* [Acknowledgements](#acknowledgements)
* [License](#license)To install `color-prefix-stream`, simply use npm:
```
npm install color-prefix stream --save
```The example below can be found [here][example] and ran using `node example.js`. It uses `color-prefix-stream` to print multiple lines using random-picked colors.
```js
'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()
```### prefixer([opts])
Returns a [split2][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][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](http://nearform.com).
## License
Copyright Matteo Collina 2016, Licensed under [MIT][].
[MIT]: ./LICENSE
[example]: ./example.js
[split2]: https://github.com/mcollina/split2
[chalk]: https://npm.im/chalk