color-converter
Allows conversion of colors with JavaScript from and to different formats and output as CSS.
This project is no longer actively maintained since it doesn't really have a USP. Maybe use the great color package instead.
Usage
The class is pretty much self-documenting. Just risk a look into color-converter.ts
. :)
A small example:
const Color = default let cssValue = Color // Create from red // Make it 20% darker // Add 40% blue // Set opacity to 50% // Returns Hex or RGBA string (depending on alpha value) console // Output: rgba(153, 0, 102, 0.5)
API
Static constructors
// Returns a random colorColor // Returns a color... // ...from another color objectColor // ...from a CSS color value (like "#aaa", "rgba(0,0,0,.5)" or "red")Color // ...from an HTML color nameColor // ...from a Hex string such as "#fff" or "#123456"Color // ...from red, green and blue each ranging from 0 to 255...Color// ...and alpha channel from 0 to 1Color // ...from hue, saturation and lightness each ranging from 0 to 1...Color// ...and alpha channel from 0 to 1Color // ...from hue, saturation and value each ranging from 0 to 1...Color// ...and alpha channel from 0 to 1Color
Converters
let color = Color // Converts the color to... // ...a string usable in CSScolor// Returns "#663399" // ...an HTML namecolor// Returns "RebeccaPurple" (returns null in case the color doesn't match any name) // ...a Hex stringcolor// Returns "#663399", returns an rgba(...) string if alpha channel isn't 1 // ...an RGB hashcolor// Returns { r: 102, g: 51, b: 153 } // ...an RGBA hashcolor// Returns { r: 102, g: 51, b: 153, a: 1 } // ...an HSL hashcolor// Returns { h: 0.8, s: 0.5, l: 0.4 } // ...an HSLA hashcolor// Returns { h: 0.8, s: 0.5, l: 0.4, a: 1 } // ...an HSV hashcolor// Returns { h: 0.75, s: 0.667, v: 0.6 } // ...an HSVA hashcolor// Returns { h: 0.75, s: 0.667, v: 0.6, a: 1 }
Properties & Modifiers
These modifiers will allow you to change a color according to your needs.
// Properties first. You can get and set those. // The alpha channel, a value from 0 to 1coloralpha // The portion of red/green/blue a value from 0 to 255colorredcolorgreencolorblue // The hue, a value from 0 to 1colorhue // The saturation as in HSV color model, a value between 0 and 1colorsaturation // The value as in HSV color model, a value between 0 and 1colorvalue // The lightness as in HSL color model, a value between 0 and 1colorlightness // Modifiers // Changes the opacity by an absolute percentage from -100 to 100color // Rotates the hue by a number of degreescolor // Changes the saturation by an absolute percentage from -100 to 100color // Basically color.saturate(number * -1)color // Changes the lightness (as in HSL) by an absolute percentage from -100 to 100color // The same as color.lighten(number * -1)color // Changes the portion of red/green/blue by an absolute percentage from -100 to 100colorcolorcolor // Inverts saturation as in HSV color modelcolor // Inverts the value as in HSV color modelcolor // Inverts the lightness as in HSL color modelcolor