Skip to content

Instantly share code, notes, and snippets.

@oscarotero
Last active Mar 20, 2018
Embed
What would you like to do?
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