Created
November 8, 2022 09:35
-
-
Save espretto/f745ce8e2631c672fbf8659b4ccd2621 to your computer and use it in GitHub Desktop.
ts: stringify css declaration
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
const kebabCase = (camelCased: string) => | |
camelCased.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); | |
export const toCssText = (styles: object) => | |
Object.keys(styles) | |
// @ts-ignore: trust input is a CSSStyleDeclaration | |
.flatMap(prop => [kebabCase(prop), ":", styles[prop], ";"]) | |
.join(""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment