Last active
May 6, 2024 05:08
-
-
Save tomhodgins/c54ea29bedff65dab75d44b172476285 to your computer and use it in GitHub Desktop.
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
function camelToKebab(string) { | |
const tag = document.createElement('span') | |
tag.dataset[string] = true | |
return tag.attributes[0].name.split(/^data-/)[1] | |
} |
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
function kebabToCamel(string) { | |
const tag = document.createElement('span') | |
tag.setAttribute(`data-${string}`, true) | |
return Object.entries(tag.dataset)[0][0] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment