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 terminal console
Install
npm i eight-colors
APIs
- eight colors: black, red, green, yellow, blue, magenta, cyan, white
- styles: reset, bold, faint, italic, underline, inverse, hidden, strike
- remove color
- log color
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"));
const redString = EC.red("red string");
console.log(redString);
const string = EC.remove(redString);
console.log(string === "red string");
EC.logColor("string", "red");
EC.logGreen('green string');
EC.logRed('red string');
EC.logCyan('cyan string');
Changelog