Package Exports
- colors-convert
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (colors-convert) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Colors convert 🍭🍬
A simple colors library.
Using colors-convert you can:
- read colors in different formats
- analyze and manipulate colors
- convert colors into different formats
- give a name to a color.
How to use
yarn add colors-convertor
npm install --save colors-convertAPI
Different color formats are supported: hex, rgb, rgba, cmyk and hsl.
🎨 Color formats
Hex
A valid hex color can be:
- long form:
#FFFFFF - short form:
#FFF - long form with opacity:
#FFFFFFFF(white with opacityFF=1).
isHex(color): boolean
Returns true if color is a valid hex, false otherwise.
Rgb
A valid rgb color is an object like this {r, g, b} with r, b, g numeric values in range [0, 255].
isRgb(color): boolean
Returns true if color is a valid rgb, false otherwise.
Rgba
A valid rgba color is an object like this {r, g, b, a} with r, g, b numeric values in range [0, 255] and a in range [0, 1].
isRgba(color): boolean
Returns true if color is a valid rgba, false otherwise.
Cmyk
A valid cmyk color is an object like this {c, m, y, k} with c, m, y, k numeric values in range [0, 100].
isCmyk(color): boolean
Returns true if color is a valid cmyk, false otherwise.
Hsl
A valid hsl color is an object like this {h, s, l} where:
h(hue):[0-359]°s(saturation):[0-100]%l(lightness):[0-100]%.
isHsl(color): boolean
Returns true if color is a valid hsl, false otherwise.
🎨 Conversion
hex2rgbOrRgba(hex): rgb | rgba: Converts a hex to a rgb or rgba color (depends on hex format)hex2rgba(hex, alpha = 1): rgba: Converts a hex to a rgba objecthex2hexWithAlpha(hex, alpha): hex: Converts a hex to another hex with the given alphahex2cmyk(hex): cmyk: Converts a hex to a cmyk. If hex is in the long format (e.g. #000000FF) it removes the last two chars because cmyk doens't support opacityhex2hsl(hex): hsl: Converts a hex object to hslrgb2hex(rgb): hex: Converts a rgb object to hexrgb2cmyk(rgb): cmyk: Converts a rgb to a cmykrgb2hsl(rgb): hsl: Converts a rgb object to hslrgba2rgb(rgba): rgb: Converts a rgba color to a rgb color removing the alpha valuergb2rgba(rgb): rgba: Converts a rgb color to a rgba color adding 1 as alphacolor2rgb(color): rgb: Converts a generic color (hex, rgb, rgba, cmyk, hsl) to rgbcmyk2rgb(cmyk): rgb: Converts a cmyk color to a rgbcmyk2hex(cmyk): hex: Converts a cmyk color to a hexcmyk2hsl(cmyk): hsl: Converts a cmyk object to hslhsl2hex(hsl): hex: Converts a hsl object to hexhsl2rgb(hsl): rgb: Converts a hsl object to rgbhsl2cmyk(hsl): cmyk: Converts a hsl object to cmyk
🎨 Name that color
name(color): string: Given a color (hex, rgb, rgba, cmyk or hsl), it returns the name of that color. It works using a list of 18315 unique color names.
🎨 Utils
color2string(color): string: Converts a color to a string format. For example:- hex:
#E6259F - rgb:
230, 37, 159 - rgba:
230, 37, 159, 1 - cmyk:
0%, 84%, 31%, 10% - hsl:
322, 79%, 52%
- hex:
color2cssString(color): string: Converts a color to a string format usable in CSS. For example:- hex:
#E6259F - rgb:
rgb(230, 37, 159) - rgba:
rgba(230, 37, 159, 1) - cmyk:
cmyk(0%, 84%, 31%, 10%) - hsl:
hsl(322, 79%, 52%)
- hex:
mix(colors: Color[], weights?: number[]): rgb: Mix two or more colors based on their weights.