Last active
November 3, 2020 16:20
-
-
Save tomhodgins/3e27a0ceff7a6e074c9e688dcbf59c90 to your computer and use it in GitHub Desktop.
This file contains 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 extractCustomProperties = (string = '') => Object.fromEntries( | |
Array.from( | |
string.matchAll(/--(?<property>[^:]+?)\s*:\s*(?<value>.*?)\s*[;}]/gus), | |
([match, property, value]) => [property, value] | |
) | |
) | |
const css = ` | |
:root { | |
--custom: property; | |
--brand-color: #0c0; | |
} | |
` | |
console.log( | |
extractCustomProperties(css) | |
) | |
// {custom: "property", brand-color: "#0c0"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment