Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
colors-convert
Advanced tools
Using colors-convert
you can:
yarn add colors-convert
or
npm install --save colors-convert
Go here to take a look at the complete API.
Different color formats are supported: hex, rgb, rgba, hsl, hsla and cmyk.
A valid hex color can be:
#rrggbb[aa]
(6/8-digit, long form)#rgb[a]
(3/4-digit, short form)
with r
, g
, b
, a
in [0-9a-fA-F]
.A valid rgb color is an object like this {r, g, b}
with r, b, g
numeric values in [0, 255]
.
A valid rgba color is an object like this {r, g, b, a}
with r, g, b
numeric values in [0, 255]
and a
in [0, 1]
.
A valid hsl color is an object like this {h, s, l}
with:
h
(hue): [0-359]°
s
(saturation): [0-100]%
l
(lightness): [0-100]%
.A valid hsl color is an object like this {h, s, l}
with:
h
(hue): [0-359]°
s
(saturation): [0-100]%
l
(lightness): [0-100]%
a
(alpha): [0-1]
.A valid cmyk color is an object like this {c, m, y, k}
with c, m, y, k
numeric values in [0, 100]
.
You can convert a color in any format to any other supported format.
from \ to | Hex | Rgb | Rgba | Hsl | Hsla | Cmyk |
---|---|---|---|---|---|---|
Hex | \ | hexToRgb | hexToRgba | hexToHsl | hexToHsla | hexToCmyk |
Rgb | rgbToHex | \ | rgbToRgba | rgbToHsl | rgbToHsla | rgbToCmyk |
Rgba | rgbaToHex | rgbaToRgb | \ | rgbaToHsl | rgbaToHsla | rgbaToCmyk |
Hsl | hslToHex | hslToRgb | hslToRgba | \ | hslToHsla | hslToCmyk |
Hsla | hslaToHex | hslaToRgb | hslaToRgba | hslaToHsl | \ | hslaToCmyk |
Cmyk | cmykToHex | cmykToRgb | cmykToRgba | cmykToHsl | cmykToHsla | \ |
Color | colorToHex | colorToRgb | colorToRgba | colorToHsl | colorToHsla | colorToCmyk |
Then there are more specific color format functions. You can also convert a Color to a redeable string format or a CSS string format. Go here to take a look at the complete API.
name(color: Color): string
: given a color (hex, rgb, rgba, hsl, hsla, cmyk), it returns the name of that color. It works using a list of 18315 unique color names.
mix(colors: Color[], weights?: number[]): rgb
: mix two or more colors based on their weights.
randomHex(): HEX
: return a random hex.
colorToHex
, color2rgba
, rgbaToHex
, cmykToRgba
, cmykToHsla
, hexToHsla
, rgbToHsla
, rgbaToHsla
, hslToRgba
, colorToCmyk
, colorToHsl
, hslToHsla
, colorToHsla
, hslaStringToObject
, hexToRgb
, hexToRgba
, shortToLongHex
color2string
, color2cssString
, hex2rgbOrRgba
, hex2rgba
, hex2hexWithAlpha
, hex2cmyk
, hex2hsl
, rgb2hex
, rgb2cmyk
, rgb2hsl
, rgb2rgba
, color2rgb
, rgbString2Object
, rgba2rgb
, rgbaString2Object
, cmyk2hex
, cmyk2rgb
, cmyk2hsl
, cmykString2Object
, hsl2hex
, hsl2rgb
, hsl2cmyk
, hslString2Object
, getRandomColor
,rgb2rgba
has optional alpha parameterColorName
type: is no more a string but an object with name, hex and rgb#00000
is not a valid hex colorGo here to see the CHANGELOG.
FAQs
A simple color library
We found that colors-convert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.