Skip to content

@longmo-utils/common / TinyColor

Class: TinyColor

Constructors

Constructor

ts
new TinyColor(color?, opts?): TinyColor;

Parameters

ParameterType
color?ColorInput
opts?Partial<TinyColorOptions>

Returns

TinyColor

Methods

isDark()

ts
isDark(): boolean;

Returns

boolean


isLight()

ts
isLight(): boolean;

Returns

boolean


getBrightness()

ts
getBrightness(): number;

Returns the perceived brightness of the color, from 0-255.

Returns

number


getLuminance()

ts
getLuminance(): number;

Returns the perceived luminance of a color, from 0-1.

Returns

number


getAlpha()

ts
getAlpha(): number;

Returns the alpha value of a color, from 0-1.

Returns

number


setAlpha()

ts
setAlpha(alpha?): this;

Sets the alpha value on the current color.

Parameters

ParameterTypeDescription
alpha?string | numberThe new alpha value. The accepted range is 0-1.

Returns

this


isMonochrome()

ts
isMonochrome(): boolean;

Returns whether the color is monochrome.

Returns

boolean


toHsv()

ts
toHsv(): Numberify<HSVA>;

Returns the object as a HSVA object.

Returns

Numberify<HSVA>


toHsvString()

ts
toHsvString(): string;

Returns the hsva values interpolated into a string with the following format: "hsva(xxx, xxx, xxx, xx)".

Returns

string


toHsl()

ts
toHsl(): Numberify<HSLA>;

Returns the object as a HSLA object.

Returns

Numberify<HSLA>


toHslString()

ts
toHslString(): string;

Returns the hsla values interpolated into a string with the following format: "hsla(xxx, xxx, xxx, xx)".

Returns

string


toHex()

ts
toHex(allow3Char?): string;

Returns the hex value of the color.

Parameters

ParameterTypeDescription
allow3Char?booleanwill shorten hex value to 3 char if possible

Returns

string


toHexString()

ts
toHexString(allow3Char?): string;

Returns the hex value of the color -with a # prefixed.

Parameters

ParameterTypeDescription
allow3Char?booleanwill shorten hex value to 3 char if possible

Returns

string


toHex8()

ts
toHex8(allow4Char?): string;

Returns the hex 8 value of the color.

Parameters

ParameterTypeDescription
allow4Char?booleanwill shorten hex value to 4 char if possible

Returns

string


toHex8String()

ts
toHex8String(allow4Char?): string;

Returns the hex 8 value of the color -with a # prefixed.

Parameters

ParameterTypeDescription
allow4Char?booleanwill shorten hex value to 4 char if possible

Returns

string


toHexShortString()

ts
toHexShortString(allowShortChar?): string;

Returns the shorter hex value of the color depends on its alpha -with a # prefixed.

Parameters

ParameterTypeDescription
allowShortChar?booleanwill shorten hex value to 3 or 4 char if possible

Returns

string


toRgb()

ts
toRgb(): Numberify<RGBA>;

Returns the object as a RGBA object.

Returns

Numberify<RGBA>


toRgbString()

ts
toRgbString(): string;

Returns the RGBA values interpolated into a string with the following format: "RGBA(xxx, xxx, xxx, xx)".

Returns

string


toPercentageRgb()

ts
toPercentageRgb(): RGBA;

Returns the object as a RGBA object.

Returns

RGBA


toPercentageRgbString()

ts
toPercentageRgbString(): string;

Returns the RGBA relative values interpolated into a string

Returns

string


toName()

ts
toName(): string | false;

The 'real' name of the color -if there is one.

Returns

string | false


toString()

Call Signature

ts
toString<T>(format): string | boolean;

String representation of the color.

Type Parameters
Type Parameter
T extends "name"
Parameters
ParameterTypeDescription
formatTThe format to be used when displaying the string representation.
Returns

string | boolean

Call Signature

ts
toString<T>(format?): string;

String representation of the color.

Type Parameters
Type Parameter
T extends ColorFormats
Parameters
ParameterTypeDescription
format?TThe format to be used when displaying the string representation.
Returns

string


toNumber()

ts
toNumber(): number;

Returns

number


clone()

ts
clone(): TinyColor;

Returns

TinyColor


lighten()

ts
lighten(amount?): TinyColor;

Lighten the color a given amount. Providing 100 will always return white.

Parameters

ParameterTypeDescription
amount?numbervalid between 1-100

Returns

TinyColor


brighten()

ts
brighten(amount?): TinyColor;

Brighten the color a given amount, from 0 to 100.

Parameters

ParameterTypeDescription
amount?numbervalid between 1-100

Returns

TinyColor


darken()

ts
darken(amount?): TinyColor;

Darken the color a given amount, from 0 to 100. Providing 100 will always return black.

Parameters

ParameterTypeDescription
amount?numbervalid between 1-100

Returns

TinyColor


tint()

ts
tint(amount?): TinyColor;

Mix the color with pure white, from 0 to 100. Providing 0 will do nothing, providing 100 will always return white.

Parameters

ParameterTypeDescription
amount?numbervalid between 1-100

Returns

TinyColor


shade()

ts
shade(amount?): TinyColor;

Mix the color with pure black, from 0 to 100. Providing 0 will do nothing, providing 100 will always return black.

Parameters

ParameterTypeDescription
amount?numbervalid between 1-100

Returns

TinyColor


desaturate()

ts
desaturate(amount?): TinyColor;

Desaturate the color a given amount, from 0 to 100. Providing 100 will is the same as calling greyscale

Parameters

ParameterTypeDescription
amount?numbervalid between 1-100

Returns

TinyColor


saturate()

ts
saturate(amount?): TinyColor;

Saturate the color a given amount, from 0 to 100.

Parameters

ParameterTypeDescription
amount?numbervalid between 1-100

Returns

TinyColor


greyscale()

ts
greyscale(): TinyColor;

Completely desaturates a color into greyscale. Same as calling desaturate(100)

Returns

TinyColor


spin()

ts
spin(amount): TinyColor;

Spin takes a positive or negative amount within [-360, 360] indicating the change of hue. Values outside of this range will be wrapped into this range.

Parameters

ParameterType
amountnumber

Returns

TinyColor


mix()

ts
mix(color, amount?): TinyColor;

Mix the current color a given amount with another color, from 0 to 100. 0 means no mixing (return current color).

Parameters

ParameterType
colorColorInput
amount?number

Returns

TinyColor


analogous()

ts
analogous(results?, slices?): TinyColor[];

Parameters

ParameterType
results?number
slices?number

Returns

TinyColor[]


complement()

ts
complement(): TinyColor;

taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js

Returns

TinyColor


monochromatic()

ts
monochromatic(results?): TinyColor[];

Parameters

ParameterType
results?number

Returns

TinyColor[]


splitcomplement()

ts
splitcomplement(): TinyColor[];

Returns

TinyColor[]


onBackground()

ts
onBackground(background): TinyColor;

Compute how the color would appear on a background

Parameters

ParameterType
backgroundColorInput

Returns

TinyColor


triad()

ts
triad(): TinyColor[];

Alias for polyad(3)

Returns

TinyColor[]


tetrad()

ts
tetrad(): TinyColor[];

Alias for polyad(4)

Returns

TinyColor[]


polyad()

ts
polyad(n): TinyColor[];

Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...) monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc...

Parameters

ParameterType
nnumber

Returns

TinyColor[]


equals()

ts
equals(color?): boolean;

compare color vs current color

Parameters

ParameterType
color?ColorInput

Returns

boolean

Properties

PropertyTypeDescription
rnumberred
gnumbergreen
bnumberblue
anumberalpha
formatColorFormatsthe format used to create the tinycolor instance
originalInputColorInputinput passed into the constructer used to create the tinycolor instance
isValidbooleanthe color was successfully parsed
gradientType?string-
roundAnumberrounded alpha

Released under the MIT License.