tinylibs / tinyrainbow

🌈 a small library to print colourful messages
MIT License
45 stars 0 forks source link

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

Open jcbhmr opened 1 year ago

jcbhmr commented 1 year ago

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

```js 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

```js 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

```js 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

```js 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

```js 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

```js 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

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

sheremet-va commented 1 month ago

From the readme it would appear that the main purpose is to print colors to the console like this

The main purpose is to be able to generate a string that can be printed in Node.js or the chrome-browser. The string can be stored separately from the console call. The interface needs to be compatible with Jest's diff config. I like the simplicity of picocolors so I went with it. Unfortunately, it doesn't print colored outputs in the browser.

I don't really know how to explain it further. All other solutions don't satisfy the use case: be small, work in Node and Chrome, provide only non-chainable calls.