Home Reference Source
import {ColorContrastCalc} from 'color-contrast-calc/lib/color-contrast-calc.js'
public class | source

ColorContrastCalc

Provides the top-level name space of this library.

Static Member Summary

Static Public Members
public static

Array of named colors defined at https://www.w3.org/TR/SVG/types.html#ColorKeywords

public static

Array of web safe colors

Static Method Summary

Static Public Methods
public static

colorFrom(colorValue: string | Array<number, number, number>, name: string): Color

Returns an instance of Color.

public static

Returns an array of named colors that satisfy a given level of contrast ratio

public static

compareFunction(colorOrder: string, keyType: string, keyMapper: function): function

Returns a function to be used as a parameter of Array.prototype.sort()

public static

hslColors(s: number, l: number, h_interval: number): Color[]

Returns an array of colors which share the same saturation and lightness.

public static

sort(colors: Color[] | String[], colorOrder: string, keyMapper: function, mode: string): Color[]

Sorts colors in an array and returns the result as a new array

Static Public Members

public static NAMED_COLORS: * source

Array of named colors defined at https://www.w3.org/TR/SVG/types.html#ColorKeywords

Properties:

NameTypeAttributeDescription
NAMED_COLORS Color[]

public static WEB_SAFE_COLORS: * source

Array of web safe colors

Properties:

NameTypeAttributeDescription
WEB_SAFE_COLORS Color[]

Static Public Methods

public static colorFrom(colorValue: string | Array<number, number, number>, name: string): Color source

Returns an instance of Color.

As colorValue, you can pass a predefined color name, or an RGB value represented as an array of Integers or a hex code such as [255, 255, 255] or "#ffff00". name is assigned to the returned instance if it does not have a name already assigned.

Params:

NameTypeAttributeDescription
colorValue string | Array<number, number, number>

name of a predefined color or RGB value

name string

Unless the instance has predefined name, the name passed to the method is set to self.name

Return:

Color

Instance of Color

public static colorsWithSufficientContrast(color: Color, level: string): Color[] source

Returns an array of named colors that satisfy a given level of contrast ratio

Params:

NameTypeAttributeDescription
color Color

base color to which other colors are compared

level string
  • optional
  • default: "AA"

A, AA or AAA

Return:

Color[]

public static compareFunction(colorOrder: string, keyType: string, keyMapper: function): function source

Returns a function to be used as a parameter of Array.prototype.sort()

Params:

NameTypeAttributeDescription
colorOrder string
  • optional
  • default: "rgb"

A left side primary color has a higher sorting precedence

keyType string
  • optional
  • default: "color"

Type of keys used for sorting: "color", "hex" or "rgb"

keyMapper function
  • optional
  • default: null

A function used to retrive key values from elements to be sorted

Return:

function

Function that compares given two colors

public static hslColors(s: number, l: number, h_interval: number): Color[] source

Returns an array of colors which share the same saturation and lightness. By default, so-called pure colors are returned.

Params:

NameTypeAttributeDescription
s number
  • optional
  • default: 100

Ratio of saturation in percentage.

l number
  • optional
  • default: 50

Ratio of lightness in percentage.

h_interval number
  • optional
  • default: 1

Interval of hues given in degrees. By default, it returns 360 hues beginning from red. (Red is included twice, because it corresponds to 0 and 360 degrees.)

Return:

Color[]

public static sort(colors: Color[] | String[], colorOrder: string, keyMapper: function, mode: string): Color[] source

Sorts colors in an array and returns the result as a new array

Params:

NameTypeAttributeDescription
colors Color[] | String[]

List of colors

colorOrder string
  • optional
  • default: "rgb"

A left side primary color has a higher sorting precedence, and an uppercase letter means descending order

keyMapper function
  • optional
  • default: null

A function used to retrive key values from elements to be sorted

mode string
  • optional
  • default: "auto"

If set to "hex", key values are handled as hex code strings

Return:

Color[]

An array of sorted colors