Reference·JavaScript · @sascom/commonjsJavaScript

TinyColor

Class in @sascom/commonjs.

API catalogue · @sascom/commonjs · Class

TypeScript#
class TinyColor

Members#

Member Kind Description
constructor Method Create a tinycolor instance of the color named.
analogous Method Gets an analogous color scheme based off of the current color.
brighten Method Brighten the color a given amount.
clone Method Gets a new instance with the current color
complement Method Gets the complement of the current color
darken Method Darken the color a given amount. Providing 100 will always return black.
desaturate Method Desaturate the color a given amount. Providing 100 will is the same as calling greyscale.
getAlpha Method Returns the alpha value of the color
getBrightness Method Returns the perceived brightness of the color, from 0-255.
getFormat Method Returns the format used to create the tinycolor instance.
getLuminance Method Returns the perceived luminance of a color, from 0-1.
getOriginalInput Method Returns the input passed into the constructer used to create the tinycolor instance.
greyscale Method Completely desaturates a color into greyscale. Same as calling desaturate(100).
isDark Method Return an indication whether the color's perceived brightness is dark.
isLight Method Return an indication whether the color's perceived brightness is light.
isValid Method Return an indication whether the color was successfully parsed.
lighten Method Lighten the color a given amount. Providing 100 will always return white.
monochromatic Method Gets a monochromatic color scheme based off of the current color.
saturate Method Saturate the color a given amount.
setAlpha Method Sets the alpha value on the current color.
spin Method Spin the hue a given amount. Calling with 0, 360, or -360 will do nothing.
splitcomplement Method Gets a split complement color scheme based off of the current color.
tetrad Method Gets a tetrad based off of the current color.
toFilter Method Returns the color represented as a Microsoft filter for use in old versions of IE.
toHex Method Returns the hex value of the color.
toHex8 Method Returns the hex 8 value of the color.
toHex8String Method Returns the hex 8 value of the color -with a # appened.
toHexString Method Returns the hex value of the color -with a # appened.
toHsl Method Returns the object as a HSLA object.
toHslString Method Returns the hsla values interpolated into a string with the following format: "hsla(xxx, xxx, xxx, xx)".
toHsv Method Returns the object as a HSVA object.
toHsvString Method Returns the hsva values interpolated into a string with the following format: "hsva(xxx, xxx, xxx, xx)".
toName Method The 'real' name of the color -if there is one.
toPercentageRgb Method Returns the object as a RGBA object.
toPercentageRgbString Method Returns the RGBA relative values interpolated into a string with the following format: "RGBA(xxx, xxx, xxx, xx)".
toRgb Method Returns the object as a RGBA object.
toRgba Method Returns the color as [r, g, b, a], every component in 0..1.
toRgbString Method Returns the RGBA values interpolated into a string with the following format: "RGBA(xxx, xxx, xxx, xx)".
toString Method String representation of the color.
triad Method Gets a triad based off of the current color.
equals Method Compares two colors. Each colors can be any color inputs.
fromFloatObject Method Create a tinycolor from components in 0..1.
fromRatio Method Create a tinycolor instance based off the relative values. Works with any color formats
isReadable Method Ensure that foreground and background color combinations meet WCAG2 guidelines.
mostReadable Method Given a base color and a list of possible foreground or background colors for that base, returns the most readable color. Optionally returns Black or White i…
random Method Returns a random color
readability Method Compares the two colors and returns the constrast between two colors as a number.

constructor#

TypeScript#
constructor(color?: ColorInput, opts?: ConstructorOptions)

Create a tinycolor instance of the color named.

Parameters#

Name Type Description
color tinycolor.ColorInput the color as one of the valid color input format.
opts tinycolor.ConstructorOptions

analogous#

TypeScript#
analogous(results?: number, slices?: number): (TinyColor)[]

Gets an analogous color scheme based off of the current color.

Parameters#

Name Type Description
results number The amount of results to return. Default value: 6.
slices number The amount to slice the input color by. Default value: 30.

brighten#

TypeScript#
brighten(amount?: number): TinyColor

Brighten the color a given amount.

Parameters#

Name Type Description
amount number The amount to brighten by. The valid range is 0 to 100. Default value: 10.

clone#

TypeScript#
clone(): TinyColor

Gets a new instance with the current color

complement#

TypeScript#
complement(): TinyColor

Gets the complement of the current color

darken#

TypeScript#
darken(amount?: number): TinyColor

Darken the color a given amount. Providing 100 will always return black.

Parameters#

Name Type Description
amount number The amount to darken by. The valid range is 0 to 100. Default value: 10.

desaturate#

TypeScript#
desaturate(amount?: number): TinyColor

Desaturate the color a given amount. Providing 100 will is the same as calling greyscale.

Parameters#

Name Type Description
amount number The amount to desaturate by. The valid range is 0 to 100. Default value: 10.

getAlpha#

TypeScript#
getAlpha(): number

Returns the alpha value of the color

getBrightness#

TypeScript#
getBrightness(): number

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

getFormat#

TypeScript#
getFormat(): string

Returns the format used to create the tinycolor instance.

getLuminance#

TypeScript#
getLuminance(): number

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

getOriginalInput#

TypeScript#
getOriginalInput(): ColorInput

Returns the input passed into the constructer used to create the tinycolor instance.

greyscale#

TypeScript#
greyscale(): TinyColor

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

isDark#

TypeScript#
isDark(): boolean

Return an indication whether the color's perceived brightness is dark.

isLight#

TypeScript#
isLight(): boolean

Return an indication whether the color's perceived brightness is light.

isValid#

TypeScript#
isValid(): boolean

Return an indication whether the color was successfully parsed.

lighten#

TypeScript#
lighten(amount?: number): TinyColor

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

Parameters#

Name Type Description
amount number The amount to lighten by. The valid range is 0 to 100. Default value: 10.

monochromatic#

TypeScript#
monochromatic(results?: number): (TinyColor)[]

Gets a monochromatic color scheme based off of the current color.

Parameters#

Name Type Description
results number The amount of results to return. Default value: 6.

saturate#

TypeScript#
saturate(amount?: number): TinyColor

Saturate the color a given amount.

Parameters#

Name Type Description
amount number The amount to saturate by. The valid range is 0 to 100. Default value: 10.

setAlpha#

TypeScript#
setAlpha(alpha: number): TinyColor

Sets the alpha value on the current color.

Parameters#

Name Type Description
alpha number The new alpha value. The accepted range is 0-1.

spin#

TypeScript#
spin(amount: number): TinyColor

Spin the hue a given amount. Calling with 0, 360, or -360 will do nothing.

Parameters#

Name Type Description
amount number The amount to spin by. The valid range is -360 to 360.

splitcomplement#

TypeScript#
splitcomplement(): [TinyColor, TinyColor, TinyColor]

Gets a split complement color scheme based off of the current color.

tetrad#

TypeScript#
tetrad(): [TinyColor, TinyColor, TinyColor, TinyColor]

Gets a tetrad based off of the current color.

toFilter#

TypeScript#
toFilter(): string

Returns the color represented as a Microsoft filter for use in old versions of IE.

toHex#

TypeScript#
toHex(): string

Returns the hex value of the color.

toHex8#

TypeScript#
toHex8(): string

Returns the hex 8 value of the color.

toHex8String#

TypeScript#
toHex8String(): string

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

toHexString#

TypeScript#
toHexString(): string

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

toHsl#

TypeScript#
toHsl(): HSLA

Returns the object as a HSLA object.

toHslString#

TypeScript#
toHslString(): string

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

toHsv#

TypeScript#
toHsv(): HSVA

Returns the object as a HSVA object.

toHsvString#

TypeScript#
toHsvString(): string

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

toName#

TypeScript#
toName(): string | false

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

toPercentageRgb#

TypeScript#
toPercentageRgb(): PRGBA

Returns the object as a RGBA object.

toPercentageRgbString#

TypeScript#
toPercentageRgbString(): string

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

toRgb#

TypeScript#
toRgb(): RGBA

Returns the object as a RGBA object.

toRgba#

TypeScript#
toRgba(): [number, number, number, number]

Returns the color as [r, g, b, a], every component in 0..1.

toRgbString#

TypeScript#
toRgbString(): string

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

toString#

TypeScript#
toString(format?: "name" | "rgb" | "prgb" | "hex" | "hex6" | "hex3" | "hex4" | "hex8" | "hsl" | "hsv"): string

String representation of the color.

Parameters#

Name Type Description
format "name" | "rgb" | "prgb" | "hex" | "hex6" | "hex3" | "hex4" | "hex8" | "hsl" | "hsv" The format to be used when displaying the string representation. The accepted values are: "rgb", "prgb", "hex6", "hex3", "hex8", "name", "hsl", "hsv".

triad#

TypeScript#
triad(): [TinyColor, TinyColor, TinyColor]

Gets a triad based off of the current color.

equals#

TypeScript#
static equals(color1?: ColorInput, color2?: ColorInput): boolean

Compares two colors. Each colors can be any color inputs.

Parameters#

Name Type Description
color1 tinycolor.ColorInput
color2 tinycolor.ColorInput

fromFloatObject#

TypeScript#
static fromFloatObject(object: { a: number; b: number; g: number; r: number }): TinyColor

Create a tinycolor from components in 0..1.

Parameters#

Name Type Description
object { a: number; b: number; g: number; r: number }

fromRatio#

TypeScript#
static fromRatio(ratio?: ColorInputWithoutInstance): TinyColor

Create a tinycolor instance based off the relative values. Works with any color formats

Parameters#

Name Type Description
ratio tinycolor.ColorInputWithoutInstance the relative color/hue values to apply to the new instance.

isReadable#

TypeScript#
static isReadable(color1: ColorInput, color2: ColorInput, wcag2?: WCAG2Options): boolean

Ensure that foreground and background color combinations meet WCAG2 guidelines.

Parameters#

Name Type Description
color1 tinycolor.ColorInput the fore color wanted.
color2 tinycolor.ColorInput the back color wanted.
wcag2 tinycolor.WCAG2Options WCAG option. If the entire object is absent, function use the default of {level:"AA",size:"small"}.

mostReadable#

TypeScript#
static mostReadable(baseColor: ColorInput, colorList: (ColorInput)[], args?: MostReadableArgs): TinyColor

Given a base color and a list of possible foreground or background colors for that base, returns the most readable color. Optionally returns Black or White if the most readable color is unreadable.

Parameters#

Name Type Description
baseColor tinycolor.ColorInput the base color.
colorList (ColorInput)[] array of colors to pick the most readable one from.
args tinycolor.MostReadableArgs and object with extra arguments

random#

TypeScript#
static random(): TinyColor

Returns a random color

readability#

TypeScript#
static readability(color1: ColorInput, color2: ColorInput): number

Compares the two colors and returns the constrast between two colors as a number.

Parameters#

Name Type Description
color1 tinycolor.ColorInput the first color to be used in the comparison.
color2 tinycolor.ColorInput the second color to be used in the comparison.