Skip to main content
Module

x/color/mod.ts>Color

A simple, fast, and comprehensive color library for Deno.
Go to Latest
class Color
import { Color } from "https://deno.land/x/color@v0.2.3/mod.ts";

Constructors

new
private
Color(
channels: number[],
type: colorTypes,
alpha?: number,
)

Properties

channels: number[]
transparency: number
type: colorTypes

Methods

Returns the alpha component of a color

Returns an array with each of the channels as a key and a transparency if it is not 1

Returns the black component of a color

Returns the blackness component of a color

Returns the blue component of a color

Converts from current type to cmyk

Returns the WCAG contrast of a color (from 1-21)

Returns the cyan component of a color

darken(factor: number)

Darkens the color by some factor

desaturate(factor: number)

Desaturates the color by some factor

fade(factor: number)

Fades the color by some factor, this has the same typecasting rules as setAlpha

Grayscales the color

Returns the green component of a color

hex()

Returns the hex string from a color

Returns the hex string from a color as well as the alpha channel

hsl()

Converts from current type to hsl

Converts from current type to hsla

hsv()

Converts from current type to hsv

Converts from current type to hsva

hue()

Returns the hue component of a color

hwb()

Converts from current type to hsb

Converts from current type to hsva

Returns if the color is dark (useful for making text black or white)

Returns if the color is light (useful for making text black or white)

lighten(factor: number)

Lightens the color by some factor

Returns the lightness component of a color

Returns the WCAG luminosity of the color

Returns the magenta component of a color

mix(mixColor: Color, weight?)

Mixes two colors by a specified weight.

Negates the color: (255, 5, 0) -> (0, 250, 255)

Returns an object with each of the values as a key

opaquer(factor: number)

Opaques the color by some factor, this has the same typecasting rules as setAlpha

red()

Returns the red component of a color

rgb()

Converts from current type to rgb

Converts from current type to rgba

Returns the decimal representation of a color

rotate(value: number)

Rotates the color by some degree

saturate(factor: number)

Saturates the color by some factor

Returns the saturation component of a color

setAlpha(value: number)

Sets the alpha component of a color. This typecasts hsl->hsla, hsv->hsva, and rgb->rgba

setBlack(value: number)

Sets the black component of a color

setBlackness(value: number)

Sets the blackness component of a color

setBlue(value: number)

Sets the blue component of a color

setCyan(value: number)

Sets the cyan component of a color

setGreen(value: number)

Sets the green component of a color

setHue(value: number)

Sets the hue component of a color

setLightness(value: number)

Sets the lightness component of a color

setMagenta(value: number)

Sets the magenta component of a color

setRed(value: number)

Sets the red component of a color

setSaturation(value: number)

Sets the saturation component of a color

setValue(value: number)

Sets the value component of a color

setWhiteness(value: number)

Sets the whiteness component of a color

setYellow(value: number)

Sets the yellow component of a color

Returns a css string representation of a color

toTransparent(type: colorTypes)

Converts from current type to a version of type with alpha value

toType(colorType: colorTypes)

Converts from current type to a specific type (by string)

Returns the value component of a color

Returns the whiteness component of a color

Returns the yellow component of a color

Static Methods

cmyk(
c: number,
m: number,
y: number,
k: number,
)

Creates a color with a cyan, magenta, yellow, and black value

hsl(
h: number,
s: number,
l: number,
)

Creates a color with a hue, saturation, and lightness value

hsla(
h: number,
s: number,
l: number,
a: number,
)

Creates a color with a hue, saturation, lightness, and alpha value

hsv(
h: number,
s: number,
v: number,
)

Creates a color with a hue, saturation, and value

hsva(
h: number,
s: number,
v: number,
a: number,
)

Creates a color with a hue, saturation, value, and alpha

hwb(
h: number,
w: number,
b: number,
)

Creates a color with a hue, whiteness, and blackness value

hwba(
h: number,
w: number,
b: number,
a: number,
)

Creates a color with a hue, whiteness, blackness, and alpha

rgb(
r: number,
g: number,
b: number,
)

Creates a color with a red, green, and blue value

rgba(
r: number,
g: number,
b: number,
a: number,
)

Creates a color with a red, green, blue, and alpha value