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

ContrastChecker

Collection of functions that check properties of given colors

Static Method Summary

Static Public Methods
public static

Calculate the contrast ratio of given colors

public static

Check if the contrast ratio of a given color against black is higher than against white.

public static

Rate a given contrast ratio according to the WCAG 2.0 criteria

public static

Calculate the relative luminance of a RGB color given as a string or an array of numbers

Static Public Methods

public static contrastRatio(foreground: string | Array<number, number, number>, background: string | Array<number, number, number>): number source

Calculate the contrast ratio of given colors

Params:

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

RGB value represented as a string (hex code) or an array of numbers

background string | Array<number, number, number>

RGB value represented as a string (hex code) or an array of numbers

Return:

number

Contrast ratio

public static isLightColor(color: string | Array<number, number, number>): boolean source

Check if the contrast ratio of a given color against black is higher than against white.

Params:

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

RGB value represented as a string (hex code) or an array of numbers

Return:

boolean

true if the contrast ratio against white is qual to or less than the ratio against black

public static ratioToLevel(ratio: number): string source

Rate a given contrast ratio according to the WCAG 2.0 criteria

Params:

NameTypeAttributeDescription
ratio number

Contrast ratio

Return:

string

A, AA or AAA if the contrast ratio meets the criteria of WCAG 2.0, otherwise "-"

public static relativeLuminance(rgb: string | Array<number, number, number>): number source

Calculate the relative luminance of a RGB color given as a string or an array of numbers

Params:

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

RGB value represented as a string (hex code) or an array of numbers

Return:

number

Relative luminance