Created
November 4, 2020 11:32
-
-
Save Sven65/a56390b18cc3b7d9ae5ebaadbaa7beae to your computer and use it in GitHub Desktop.
Small script for exporting https://flatuicolors.com/ palettes to scss
This file contains hidden or 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
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