Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function parseColor(colorStr) {
if (!this.div) {
this.div = document.createElement('div');
this.div.style.hidden = true;
document.body.appendChild(this.div)
}
this.div.style.color = colorStr;
if (this.div.style.color === "")
this.div.style.color = `#${colorStr}`;
let style = window.getComputedStyle(this.div);
let colors = style.color.match(/\d+/g).map(a => parseInt(a, 10));
return new Uint8Array(colors);
}
function withdelay(values, delay) {
return {
[Symbol.iterator]: function* () {
for (let i of values) {
yield new Promise(resolve => {
setTimeout(_ => resolve(i), delay);
});
}
}
};
}
async function run() {
for (let color of withdelay(["red", "purple", "blue"], 500)) {
console.log(parseColor(await color));
}
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment