Last active
March 20, 2018 21:26
-
-
Save oscarotero/44021680411e30bd4a6bd6410167c6e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const contrast = require('wcag-contrast'); | |
const parse = require('csv-parse'); | |
const fs = require('fs'); | |
let counter = 0; | |
parse(fs.readFileSync('colors.csv'), {from: 2}, (err, result) => { | |
for (let row of result) { | |
let [slug, background, foreground] = row; | |
background = val(background, '#FFFFFF'); | |
foreground = val(foreground, '#000000'); | |
const score = contrast.hex(background, foreground); | |
const level = contrast.score(score); | |
if (level !== 'AAA') { | |
console.log(''); | |
console.log(contrast.score(score) || '-', score); | |
console.log(`https://historia-arte.com/obras/${slug}`); | |
console.log(`http://leaverou.github.io/contrast-ratio/#%23${foreground.substr(1)}-on-%23${background.substr(1)}`); | |
console.log(''); | |
console.log('=========='); | |
++counter; | |
} | |
} | |
console.log(`${counter} combinacións con pouco contraste`); | |
}); | |
function val(value, def) { | |
if (!value || value === 'NULL') { | |
return def; | |
} | |
if (value === 'white') { | |
return '#FFFFFF'; | |
} | |
if (value === 'black') { | |
return '#000000'; | |
} | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment