npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

watercolor

v0.0.2

Published

Watercolor is a Stream 2 Transform stream that will output styled and colored text. Pipe a stream or write to it directly. Outputted text will be formatted based on the options passed into the instance.

Downloads

5

Readme

watercolor

A very simple transform stream that outputs text streams to the console with color and style. You can either pipe in a readable stream or write to it directly.

watercolor uses Node's Streams 2 API to do its dirty work!

install

npm install watercolor

example

####Write directly to it :

var Watercolor = require('watercolor'),
    watercolor = Watercolor({
        style : 'normal',
        color : 'red'
    });
    
watercolor.write("Hello\n");
watercolor.end("World\n");
watercolor.pipe(process.stdout);

The call to watercolor.write will output Hello in red text with no styling to the console and insert a line break.

The call to watercolor.end will output World in red text with no styling to the console, insert a line break, and finally end the stream. goodbye!

####Pipe a readable stream to it :

var Watercolor = require('watercolor'),
    watercolor({
        style : 'underline',
        color : 'yellow'
    }),
    fs = require('fs'),
    readableStream = fs.createReadStream('./path/to/file');

readableStream.pipe(watercolor).pipe(process.stdout);

The above code will send all of the contents of readableStream into watercolor and watercolor will output the text to process.stdout underlined with yellow text.

usage

I've mainly been using this in my test runner to output a colored Summery report so I can easily see if tests pass/fail by color. You can hook this into child_process stdout and stderr to get realtime color queues if there are errors occurring with the other node processess you are running.

#####Color seperate child_process.stdout and child_process.stderr

var Watercolor = require('watercolor'),
    errTxt = watercolor({
        color : 'error'
    }),
    successTxt = watercolor({
        color : 'success'
    }),
    spawn = require('child_process').spawn(),
    child = spawn('node', ['myChild.js']);
    
child.process.stderr.write("Something went wrong! I will print in RED\n");
child.process.stdout.write("I\'m just doing what I should be doing, and in GREEN\n");

child.stdout.pipe(successTxt).pipe(process.stdout);
child.stderr.pipe(errTxt).pipe(process.stdout);

child.on('exit', function(exitcode) {
    (exitcode ? errTxt : successTxt).write("Ended with exitcode : " + exitcode);
});

The above code will format the child's stdout to print green text out to the console.

Child's stderr will be formatted as red text out to the console.

The exitcode statement will print either green or red depending on the outcome.

Note :

success is mapped to the color green.

error is mapped to red.

warn is mapped to yellow.

Another possible use case would be to color seperate I/O from different sources. Like if you have multipe Databases you can color seperate the log output to make it easier to see what is going on with your application.

options

You can initialize watercolor with an options object containing color and/or style.

#####example

var watercolor = require('watercolor'),
    greenText = watercolor({
        color : 'green',
        style : 'underline'
    });

greenText.write("This text will be green and also underlined!\n");

##.color() method

This method takes a string argument. Simply pass in the color you want to change to.

#####example watercolor.color('blue');

Note :

Passing in 'normal' to this method will set color back to your default text color.

##.style() method

This method takes a string argument. Simply pass in the style you want to change to.

#####example watercolor.style('underline');

Note :

Passing in 'normal' to this method will set color back to your default style...which is no style.

##Chainable API

These methods are chainable so you do stuff like :

watercolor.color('green').style('blink');

This will change the color to green and style to blink

watercolor.color('red');

This will change the color to red and style still be blink

watercolor.color('yellow').style('normal');

This is change the color to yellow and change the style to normal or no style.

##available colors

black white red green gray

yellow blue cyan magenta

normal success warn error

##available styles

underline blink normal

Note :

I realize that there are a few other options such as bold or italic that I've seen elsewhere but when I tested them on my computer (Mac OSX Lion) they did not work. I didn't want to put anything in here that I could not test myself. If you know of any colors or styles that do work and should be included please feel free to file an issue.

tests

npm test

Look in the test directory for some more details

license

MIT