Skip to content

How does this package compare to other Node.js color libraries? #2

@jcbhmr

Description

@jcbhmr

This library was created to support Jest assertions which use ANSI colors to display errors even though it's not used in an actual project yet.

👆 That makes it seem like there was a particular issue that you had with the other npm color libraries that you wanted to solve by making this one. I'm wondering what that particular issue is so that I can better understand the purpose behind this package. From the readme it would appear that the main purpose is to print colors to the console like this:

import c from "tinyrainbow"
console.log(c.red("Hello red world!"))

And there's also a note about this package being a fork of picocolors:

A small (~ 6 kB unpacked) fork of picocolors with support for exports field.

I'm particularly interested to know how this package improves over the picocolors package.

But there are a number of other color packages that do similar (if not identical) things. What sets this one apart? 🤔

https://www.npmjs.com/package/colors

Details
import * as colors from "colors/safe"
console.log(colors.green('hello')); // outputs green text
console.log(colors.red.underline('i like cake and pies')) // outputs red underlined text
console.log(colors.inverse('inverse the color')); // inverses the color
console.log(colors.rainbow('OMG Rainbows!')); // rainbow
console.log(colors.trap('Run the trap')); // Drops the bass

https://www.npmjs.com/package/chalk

Details
import chalk from 'chalk';

// Combine styled and normal strings
console.log(chalk.blue('Hello') + ' World' + chalk.red('!'));

// Compose multiple styles using the chainable API
console.log(chalk.blue.bgRed.bold('Hello world!'));

// Pass in multiple arguments
console.log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));

// Nest styles
console.log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));

// Nest styles of the same type even (color, underline, background)
console.log(chalk.green(
	'I am a green line ' +
	chalk.blue.underline.bold('with a blue substring') +
	' that becomes green again!'
));

// ES2015 template literal
console.log(`
CPU: ${chalk.red('90%')}
RAM: ${chalk.green('40%')}
DISK: ${chalk.yellow('70%')}
`);

// Use RGB colors in terminal emulators that support it.
console.log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
console.log(chalk.hex('#DEADED').bold('Bold gray!'));

https://github.com/jorgebucaran/colorette 🌟 this one seems like almost a carbon-copy of this package

Details
import { blue, bold, underline } from "colorette"

console.log(`
  There's a ${underline(blue("house"))},
  With a ${bold(blue("window"))},
  And a ${blue("corvette")}
  And everything is blue
`)

console.log(bold(`I'm ${blue(`da ba ${underline("dee")} da ba`)} daa`))

import { createColors } from "colorette"

const { blue } = createColors({ useColor: false })

console.log(blue("Blue? Nope, nah"))

https://github.com/doowb/ansi-colors

Details
import c from 'ansi-colors';

console.log(c.red('This is a red string!'));
console.log(c.green('This is a red string!'));
console.log(c.cyan('This is a cyan string!'));
console.log(c.yellow('This is a yellow string!'));

https://www.npmjs.com/package/cli-color

Details
import clc from "cli-color"
console.log(clc.red("Text in red"));
console.log(clc.red.bgWhite.underline("Underlined red text on white background."));
console.log(clc.red("red") + " plain " + clc.blue("blue"));
console.log(clc.red("red " + clc.blue("blue") + " red"));

https://github.com/lukeed/kleur

Details
import kleur from 'kleur';

// basic usage
kleur.red('red text');

// chained methods
kleur.blue().bold().underline('howdy partner');

// nested methods
kleur.bold(`${ white().bgRed('[ERROR]') } ${ kleur.red().italic('Something happened')}`);

const { yellow, red, cyan } = kleur

console.log(yellow(`foo ${red().bold('red')} bar ${cyan('cyan')} baz`));
console.log(yellow('foo ' + red().bold('red') + ' bar ' + cyan('cyan') + ' baz'));

https://github.com/xpl/ansicolor

Details
import { green, inverse, bgLightCyan, underline, dim } from 'ansicolor'
console.log ('foo' + green (inverse (bgLightCyan ('bar')) + 'baz') + 'qux')
console.log (underline.bright.green ('foo' + dim.red.bgLightCyan ('bar'))) // method chaining

This ties in with my #1 idea to re-invent this package as *the* cross-platform color package; a niche that isn't yet filled (all these are Node.js only)
...instead of repeating an oversaturated niche.
👆 but again this is an IDEA and I don't mean to sound like I'm diminishing your VALID USECASE or your code work. this is just a clarification of why (helpful for other users of this package too to know if it's what they want! also helps to know "why tinyrainbow instead of $X?")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions