Helper functions for WCAG contrast criteria.
According to Web Content Accessibility Guidelines (WCAG) 2.1 - #1.4.3 contrast, the intent of these Success Criteria are to provide enough contrast between text and its background so that it can be read by people with moderately low vision. Developer should take care of the colors used in website meet these criteria.
WCAG Contrast Util provides several utils function to calculate these standard. Including contrast ratio, relative luminance, large scale text and also handy utils to transform HEX color, combining multiple translucent color, mapping typography weight keyword and so on.
Demo Page available for quick test.
View full document for more usages- created by TypeDoc
Features
#HEX
with level-4 color support (3,4,6 and 8 digit)What we got
npm install wcag-contrast-util
All-in-one Contrast Function
import { isAA } from 'wcag-contrast-util'
it('check AA and AAA', () => {
// 6.38
const A = { color: '#57606A', size: 14 }
// 5.19
const B = { color: '#0969DA', size: 14 }
expect(isAA(A, '#FFF')).toBe(true)
expect(isAA(B, '#FFF')).toBe(true)
expect(isAAA(B, '#FFF')).toBe(false)
expect(isAAA(A, '#FFF')).toBe(false)
expect(isAAA({ ...A, size: 24 }, '#FFF')).toBe(true)
})
Generated using TypeDoc