Skip to main content
Version: 1.1.0

toColor

Using

Convert a color of one type to another.

Demo - use JSON
toColor(
,
,
)
"cmyk(0%, 79%, 95%, 5%)"

Arguments

ArgumentTypeDescriptionPossible ValuesExample
colornumber[]
object
string
Any color in any format.[15, 76, 213]
{r: 255, g: 14, b: 148 }
"cmyk(63, 69, 5.5, 34)"
"#F33333"
{h: 200, s: 50, v: 45}
tostringReturn type."object"
"rgb-object"
"rgb-array"
"rgb-string"
"cmyk-object"
"cmyk-array"
"cmyk-string"
"hex-string"
"hsv-object"
"hsv-array"
"hsv-string"
"hsv-array"
fromColorTypestringThe color from which we will get the result. Can help when the source value is not defined."rgb"
"cmyk"
"hex"
"hsv"
"cmyk"

Returns

number[] | object | string — Returns the color in one of the formats.

Examples

Quick view

toColor([93, 255, 101], 'rgb-object');
// { r: 93, g: 255, b: 101 }

toColor({ c: 64, m: 21, y: 99, k: 2 }, 'rgb-array');
// [90, 197, 2]

toColor({ r: 9.8, g: 32, b: 11 }, 'rgb-string');
// rgb(9, 32, 11)

toColor('rgb(190,88,17)', 'cmyk-string');
// 'cmyk(0%, 54%, 91%, 25%)'

toColor({ c: 242, m: 52, y: 11, k: 10 }, 'hsv-object');
// { h: 208, s: 100, v: 80 }

Resources

📦 Since:1.0.1
📦 Last updated:1.1.0
📦 Available in:1.3.0