What is colornames?
The 'colornames' npm package allows you to convert color names to their corresponding hexadecimal color codes. It is useful for developers who need to work with color names and require their hex values for web development, design, or other applications.
What are colornames's main functionalities?
Convert color name to hex
This feature allows you to convert a color name (e.g., 'red') to its corresponding hexadecimal color code (e.g., '#ff0000').
const colornames = require('colornames');
const hexColor = colornames('red');
console.log(hexColor); // Output: '#ff0000'
Handle case-insensitive color names
The package can handle color names in a case-insensitive manner, making it flexible for user input.
const colornames = require('colornames');
const hexColor = colornames('Red');
console.log(hexColor); // Output: '#ff0000'
Return undefined for unknown color names
If an unknown color name is provided, the package returns 'undefined', allowing you to handle errors or invalid inputs gracefully.
const colornames = require('colornames');
const hexColor = colornames('unknownColor');
console.log(hexColor); // Output: undefined
Other packages similar to colornames
color-name
The 'color-name' package provides a list of color names and their corresponding RGB values. Unlike 'colornames', which converts color names to hex codes, 'color-name' focuses on RGB values.
color-convert
The 'color-convert' package allows for conversion between various color models, including RGB, HSL, and hex. It offers more comprehensive color conversion functionalities compared to 'colornames'.
color
The 'color' package provides a wide range of color manipulation and conversion utilities, including conversion between color models and color space manipulation. It is more feature-rich compared to 'colornames'.
colornames
Convert color names to HEX color values.


Installation
Component
$ component install timoxley/colornames
Node/Browserify
$ npm install colornames
Example
var toHex = require('colornames')
VGA color names
toHex('red')
toHex('blue')
CSS color names
toHex('lightsalmon')
toHex('mediumvioletred')
Get meta data about a color
toHex.get('red')
{
name: "red",
css: true,
value: "#FF0000",
vga: true
}
Conversion is case-insensitive
toHex('Blue')
toHex('BLUE')
toHex('BlUe')
API
colornames(name)
Get HEX code for a color name, or undefined
if unknown.
.get(name)
All known data about color, including whether valid VGA or CSS color
name.
.get.vga(name)
HEX code for a color name, only if the color is a valid VGA color
name.
.get.css(name)
HEX code for a color name, only if the color is a valid CSS color
name.
###.all()
Get all color names data.
License
MIT
Complete Color Map
