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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-styl-rgb

v1.0.0

Published

simple bash console rgb syling

Readme

node-styl-rgb

simple bash console rgb syling. like node-styl for 256 and 16m color terminals.

Install :

npm install node-styl-rgb

Add colors and styles to your logs :

const { styl } = require('node-styl-rgb');
// or
import styl from 'node-styl-rgb';
...
console.log(""+styl('hello').front([80,255,0]).back([30,0,120]).underline);

Use preformated style with the property theme :

...
const title = styl().front([80,255,0]).back([30,0,120]).underline.theme;
console.log("this is "+title(" A TITLE "));
console.log("this is "+title(" AN OTHER TITLE "));

Clean rendered styles to handle text length :

...
const styled = "this is "+title(" A TITLE ");
const text = styl.none(styled);
console.log("styled=","'"+styled+"'",' length=',text.length);

styl will detect automaticly if your terminal handles true colors. You can force rgb type by importing it instead of styl. available rgb displays are :

  • types :
    • c256 : 256 colors. require('node-styl-rgb').c256
    • c16m : 16M colors. require('node-styl-rgb').c16m

available properties are :

  • theme : theme renderer

  • text : unstyled text content

  • styles :

    • bold or b
    • italic or i
    • underline or u
    • inverse
    • blink
    • strikethrough or s
  • front colors :

    • white
    • grey
    • black
    • blue
    • cyan
    • green
    • magenta
    • red
    • yellow
  • back colors :

    • whiteBG
    • greyBG
    • blackBG
    • blueBG
    • cyanBG
    • greenBG
    • magentaBG
    • redBG
    • yellowBG

available methods are :

  • methods :
    • front : sets standard or rgb front color
    • back : sets standard or rgb back color
    • style : sets styles
    • string : Change contents
    • parse : parse contents characters

front : sets standard or rgb front color

/**
Sets front color
@param input standard (ex:'red') or custom characters rgb color value
(ex:'#f00' or '#ff0000' or [255,0,0] or 0xff0000)
or number (red channel 0-255) if v2 & v3 are numbers.
@param v2 green channel 0-255
@param v3 blue channel 0-255
@returns styl
*/
front(input: RgbInputType | null, v2?: number, v3?: number): Styl

back : sets standard or rgb back color

/**
Sets background color
@param input standard (ex:'red') or custom background rgb color value
(ex:'#f00' or '#ff0000' or [255,0,0] or 0xff0000)
or number (red channel 0-255) if v2 & v3 are numbers.
@param v2 green channel 0-255
@param v3 blue channel 0-255
@returns styl
*/
back(input: RgbInputType | null, v2?: number, v3?: number): Styl

style : sets styles

/**
sets styles
@param value can be a style name like "bold" or a list of styles like "bold,i,u" or ["bold","i","u"]
@returns
*/
style(value: string | string[]): Styl

string : Change contents

/**
Sets a new content
@param text
*/
string(text: string): Styl

parse : parse contents characters

/**
Parses string characters keeping trac of relatve position
@param callback
@returns
*/
parse(callback: (v: ParseCallbackDataType) => void): string

Exemples

Exemple 1

Base use exemple : simple title.

console.log("-".repeat(10) + "|" + styl("node-styl demo").green.bold + "|" + "-".repeat(10));

Exemple 2

Recursive styling.

console.log('' 
	+ styl('test1 ' + styl('custom ').front('#08f')
	+ styl('green ').back([100, 255, 50]).black
	+ styl(' cyan ').cyan.italic.bold
	+ styl('un' + styl('der').red + 'line').u).green + ' ');

image info

Exemples with parse

Exemple 3

Use parse to make simple linear gradient.

console.log(
	styl('gradient ' + styl('underlined').u + ' text')
		.parse(obj => obj.styl
			.back([255 * obj.colP, 0, 0])
			.front([255, 255 * obj.colP, 255])
		)
	+ '');

image info

Exemple 4

Use parse to make 2d linear gradient.

console.log(
	styl("gradient displayed\non multiple\nrows with some\n2d variations").parse(obj => {
		obj.styl.front([255 * (1 - obj.colP), 255 * obj.colP, 255 * obj.rowP]);
	}) + ""
);

image info

Exemple 4

Use parse to draw a box.

console.log("* box :");
console.log(
	styl(
		[
			"+---------------+",
			"|               |",
			"|  " + styl(`checkerboard`).bold + " |",
			"|     in a      |",
			"|      box      |",
			"|               |",
			"+---------------+",
		].join("\n")
	).parse(obj => {
		if ("+-|".includes(obj.char)) {
			obj.styl.back([255 * obj.colP, 255 * obj.rowP, 255 * (1 - obj.colP * obj.rowP)]).hidden;
		} else if (Math.round(obj.col * 0.5 + obj.row) % 2) obj.styl.back("#444");
	}) + ""
);

image info