// @flow import getLuminance from './getLuminance' /** * Returns the contrast ratio between two colors based on * [W3's recommended equation for calculating contrast](http://www.w3.org/TR/WCAG20/#contrast-ratiodef). * * @example * const contrastRatio = getContrast('#444', '#fff'); */ export default function getContrast(color1: string, color2: string): number { const luminance1 = getLuminance(color1) const luminance2 = getLuminance(color2) return parseFloat( (luminance1 > luminance2 ? (luminance1 + 0.05) / (luminance2 + 0.05) : (luminance2 + 0.05) / (luminance1 + 0.05) ).toFixed(2), ) }