UNPKG

@peculiar/color

Version:

Library for color manipulation and conversion in JavaScript.

12 lines 441 B
import { getLuminance } from './get_luminance'; /** * Calculates the contrast ratio between two colors. * * Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests */ export function getContrastRatio(foreground, background) { var lumA = getLuminance(foreground); var lumB = getLuminance(background); return (Math.max(lumA, lumB) + 0.05) / (Math.min(lumA, lumB) + 0.05); } //# sourceMappingURL=get_contrast_ratio.js.map