Skip to content

Instantly share code, notes, and snippets.

@phlego
Created October 25, 2020 21:14
Show Gist options
  • Save phlego/94fbe6c4f5dbe457746965f71af47afc to your computer and use it in GitHub Desktop.
Save phlego/94fbe6c4f5dbe457746965f71af47afc to your computer and use it in GitHub Desktop.
function serializeCSS(cssProperties: CSSProperties | undefined): string {
if (!cssProperties) return '';
let cssString = '';
for (const [key, value] of Object.entries(cssProperties)) {
cssString += key.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) + ':' + value + ';';
}
return cssString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment