Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jcbhmr opened this issue Jul 18, 2023 · 0 comments
Open

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

jcbhmr opened this issue Jul 18, 2023 · 0 comments

Comments

@jcbhmr
Copy link
Member

jcbhmr commented Jul 18, 2023

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

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

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

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

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

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

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

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?")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant