Colore JS

Search documentation

Find a function or jump to a section.
v2.0.1

simulate

simulate previews how a color might appear with color vision deficiency. Compare chart or UI colors under the same simulation to find pairs that may be hard to tell apart.

Example

import { colore } from 'colore-js';
import { simulate } from 'colore-js/fn';

colore('#ef4444').simulate('protanopia').css(); // '#7a7a42'
simulate('#ef4444', 'protanopia');              // '#7a7a42'

Syntax

colore(color).simulate(type: ColorBlindnessType): Color
simulate(color: ColorInput, type: ColorBlindnessType): string

Parameters

NameTypeDescription
colorColorInputThe original color. Its alpha carries through to the result.
typeColorBlindnessType'protanopia', 'protanomaly', 'deuteranopia', 'deuteranomaly', 'tritanopia', 'tritanomaly', 'achromatopsia' or 'achromatomaly'.

Returns

The method returns a Color. The function returns a CSS string, using hex when the result fits sRGB.

Throws

A ColorError for invalid colors or an unsupported simulation type.

Compare red and green chart series

import { simulate } from 'colore-js/fn';

simulate('#ef4444', 'deuteranopia'); // '#9a9a35'
simulate('#10b981', 'deuteranopia'); // '#9b9b85'

These colors move closer in hue under the simulation. Add labels or change the line pattern when distinguishing the two series matters.