Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Last active July 6, 2019 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tomhodgins/c54ea29bedff65dab75d44b172476285 to your computer and use it in GitHub Desktop.
Save tomhodgins/c54ea29bedff65dab75d44b172476285 to your computer and use it in GitHub Desktop.
function camelToKebab(string) {
const tag = document.createElement('span')
tag.dataset[string] = true
return tag.attributes[0].name.split(/^data-/)[1]
}
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