Skip to content

Instantly share code, notes, and snippets.

@oscarotero
Last active March 20, 2018 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarotero/44021680411e30bd4a6bd6410167c6e9 to your computer and use it in GitHub Desktop.
Save oscarotero/44021680411e30bd4a6bd6410167c6e9 to your computer and use it in GitHub Desktop.
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