Skip to content

Instantly share code, notes, and snippets.

@makakoa
makakoa / inline-hover-styles.css
Created August 24, 2023 19:34
Add CSS hover styles with inline styles using
*[style*="--bg-default"] {
background: var(--bg-default);
}
*[style*="--bg-hover"]:hover {
background: var(--bg-hover);
}
*[style*="--bg-selected"].selected {
background: var(--bg-selected);
}
@makakoa
makakoa / note.md
Created August 24, 2023 20:08
JS Style Objects to CSS Strings

Some example functions to map JS Object representations of CSS to CSS strings

inlineStylesToString stringifies flat inline style object. Eg:

inlineStylesToString({
  backgroundColor: '#fff',
  width: '100%',
  opacity: 1
}) 
// => 'background-color: #fff; width: 100%; opacity: 1; '
@makakoa
makakoa / chunkWork.js
Last active August 25, 2023 03:18
Chunking heavy JS workloads with generator functions (function*)
const nth = 1000000;
console.time("fib");
chunkWork(fibonacciDigits(nth)).then((digits) => {
console.log("The ", nth, " fibonacci number has ", digits, " digits");
console.timeEnd("fib");
});
function chunkWork(workGenerator, minChunkTime = 50) {
return new Promise((resolve) => {
function processChunk() {