Skip to content

Instantly share code, notes, and snippets.

@orourkek
Created March 11, 2019 21:52
Show Gist options
  • Save orourkek/2b3bc430c1e98e64e7795309b11fa0ee to your computer and use it in GitHub Desktop.
Save orourkek/2b3bc430c1e98e64e7795309b11fa0ee to your computer and use it in GitHub Desktop.
Grab flatuicolors.com palette as sass variables
printSassColors();
function toCamelCase(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => {
return index == 0 ? letter.toLowerCase() : letter.toUpperCase();
}).replace(/\s+/g, '');
}
function getColors() {
const colors = {};
document.querySelectorAll('.color').forEach((element) => {
const name = toCamelCase(element.querySelector('span').innerHTML);
const color = element.getAttribute('style')
.replace(/^background: /, '')
.replace(/;$/, '');
colors[name] = color;
});
return colors;
}
function printSassColors() {
const colors = getColors();
console.log(
Object.keys(colors).map((name) => {
return `\$${name}: ${colors[name]};`;
}).join('\n')
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment