What is eight-colors?
The eight-colors npm package is a utility for working with colors in JavaScript. It provides a variety of functions for color manipulation, conversion, and formatting.
What are eight-colors's main functionalities?
Color Conversion
This feature allows you to convert colors from one format to another. In this example, a hex color code is converted to its RGB representation.
const eightColors = require('eight-colors');
const rgb = eightColors.hexToRgb('#ff5733');
console.log(rgb); // { r: 255, g: 87, b: 51 }
Color Manipulation
This feature allows you to manipulate colors, such as lightening or darkening them. In this example, the color is lightened by 20%.
const eightColors = require('eight-colors');
const lighterColor = eightColors.lighten('#ff5733', 0.2);
console.log(lighterColor); // '#ff8a66'
Color Formatting
This feature allows you to format colors into different string representations. In this example, an RGB object is formatted into an RGB string.
const eightColors = require('eight-colors');
const formattedColor = eightColors.formatRgb({ r: 255, g: 87, b: 51 });
console.log(formattedColor); // 'rgb(255, 87, 51)'
Other packages similar to eight-colors
color
The 'color' package is a comprehensive library for color conversion and manipulation. It supports a wide range of color models and provides extensive methods for color operations. Compared to eight-colors, it offers more advanced features and a larger set of supported color models.
chroma-js
Chroma.js is a powerful library for color manipulation and conversion. It provides a rich API for working with colors, including blending, interpolation, and color scales. Chroma.js is more feature-rich and versatile compared to eight-colors, making it suitable for complex color operations.
tinycolor2
TinyColor is a small, fast library for color manipulation and conversion. It offers a simple API for common color operations and supports various color formats. TinyColor2 is lightweight and easy to use, making it a good alternative to eight-colors for basic color tasks.
Eight Colors
Eight colors for the console
Install
npm i eight-colors
Features
- Eight Colors:
black
, red
, green
, yellow
, blue
, magenta
, cyan
, white
- Background and Bright
- Styles: reset, bold, faint, italic, underline, inverse, hidden, strike
- Remove colors
- Log colors
- ESM/CJS
- TypeScript
- env
NO_COLOR
FORCE_COLOR
and flags --no-color
--color
- 0 dependencies
- 2.6K Size
Usage
const EC = require("eight-colors");
console.log(EC.red('red string'));
console.log(EC.bg.red('red background'));
console.log(EC.br.red('bright red string'));
console.log(EC.br.bg.red('bright red background'));
console.log(EC.italic('italic text'));
console.log(EC.underline('underline text'));
console.log(EC.green(EC.underline('green underline text')));
const redString = EC.red('red string');
console.log(redString);
const string = EC.remove(redString);
console.assert(string === 'red string');
const res = EC.logRed('string1', 'string2');
console.assert(EC.remove(res) === 'string1 string2');
EC.logGreen('log green');
EC.logRed('log red');
EC.logCyan('log cyan');
EC.logBlack('log black');
EC.logWhite('log white');
EC.log('log 2 arguments', '2');
EC.logGreen('logGreen 2 arguments', '2');
EC.logMagenta('logMagenta 3 arguments', '2', '3');
EC.disabled = true;
EC.logRed('disabled = true log default');
EC.disabled = false;
EC.logRed('disabled = false log red');
APIs
EC.black(str)
EC.red(str)
EC.green(str)
EC.yellow(str)
EC.blue(str)
EC.magenta(str)
EC.cyan(str)
EC.white(str)
EC.bg.black(str)
EC.bg.red(str)
EC.bg.green(str)
EC.bg.yellow(str)
EC.bg.blue(str)
EC.bg.magenta(str)
EC.bg.cyan(str)
EC.bg.white(str)
EC.br.black(str)
EC.br.red(str)
EC.br.green(str)
EC.br.yellow(str)
EC.br.blue(str)
EC.br.magenta(str)
EC.br.cyan(str)
EC.br.white(str)
EC.br.bg.black(str)
EC.br.bg.red(str)
EC.br.bg.green(str)
EC.br.bg.yellow(str)
EC.br.bg.blue(str)
EC.br.bg.magenta(str)
EC.br.bg.cyan(str)
EC.br.bg.white(str)
EC.reset(str)
EC.bold(str)
EC.faint(str)
EC.italic(str)
EC.underline(str)
EC.inverse(str)
EC.hidden(str)
EC.strike(str)
EC.remove(str)
EC.log(str)
EC.logBlack(str)
EC.logRed(str)
EC.logGreen(str)
EC.logYellow(str)
EC.logBlue(str)
EC.logMagenta(str)
EC.logCyan(str)
EC.logWhite(str)
EC.disabled = true|false
Browser Console
Usage is the same as above, and provides an additional UMD bundle (1.35 KB)
<script src="path-to/eight-colors/dist/eight-colors.js"></script>
<script>
const EC = window['eight-colors'];
console.log(EC.red('red string'));
</script>
Links