color-convert
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
color-name | 1.1.3 | 3.98 kB | MIT | prod |
Color-convert is a powerful JavaScript library for color conversions. It offers the ability to switch between various color spaces including rgb
, hsl
, hsv
, hwb
, cmyk
, ansi
, ansi16
, hex
strings, and CSS keywords
. This capability makes it an essential tool for designers, developers, and anyone with a need to manipulate colors in JavaScript.
You can utilize color-convert in your JavaScript application by first installing it using the npm package manager. Run the command npm install color-convert
in your terminal. Once installed, require the color-convert module in your code file. Use the conversion function you need by accessing the property of the 'from' and 'to' colors you are looking for.
A simple example of usage:
var convert = require('color-convert');
convert.rgb.hsl(140, 200, 100); // Converts RGB to HSL
convert.keyword.rgb('blue'); // Converts 'blue' keyword to RGB
You can also convert 'from' color functions that have a hidden property called .channels
indicating the number of channels it expects. Return values are rounded by default, to get unrounded results, simply add .raw
to the function:
var convert = require('color-convert');
convert.rgb.cmyk(167, 255, 4); // Converts RGB to CMYK
convert.rgb.cmyk.raw(167, 255, 4); // Returns unrounded results of RGB to CMYK conversion
All functions that accept multiple arguments also support the passing of an array as an argument:
var convert = require('color-convert');
convert.rgb.hex(123, 45, 67); // Converts RGB to Hex
convert.rgb.hex([123, 45, 67]); // Converts RGB array to Hex
The documentation for color-convert is primarily found on its GitHub page (https://github.com/Qix-/color-convert). Detailed explanations of the conversion functions and usage examples are provided in the conversions.js file in the repository. Furthermore, the README file on the GitHub page offers comprehensive guidance on installation, API, usage, and contributing.