Skip to content

Instantly share code, notes, and snippets.

@Sven65
Created November 4, 2020 11:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sven65/a56390b18cc3b7d9ae5ebaadbaa7beae to your computer and use it in GitHub Desktop.
Save Sven65/a56390b18cc3b7d9ae5ebaadbaa7beae to your computer and use it in GitHub Desktop.
Small script for exporting https://flatuicolors.com/ palettes to scss
exportToSCSS = () => {
function camelize(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) {
if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces
return index === 0 ? match.toLowerCase() : match.toUpperCase();
});
}
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
container = document.querySelector("#app > div.bigpalette-container > div.colors")
let data = ''
for (const item of container.children) {
let colorName = camelize(item.querySelector('span').innerHTML)
let bgColor = item.style.background.replace('rgb(', '').replace(')', '').split(',')
let r = parseInt(bgColor[0], 10)
let g = parseInt(bgColor[1], 10)
let b = parseInt(bgColor[2], 10)
let hexColor = rgbToHex(r, g, b)
data = `${data}\n$${colorName}: ${hexColor};`
}
console.log(data)
}
exportToSCSS()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment