Skip to content

Instantly share code, notes, and snippets.

@bkardell
Forked from tomhodgins/camel-to-kebab.js
Last active July 6, 2019 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkardell/cff42ab863dbd5cbb5d28d9309eab712 to your computer and use it in GitHub Desktop.
Save bkardell/cff42ab863dbd5cbb5d28d9309eab712 to your computer and use it in GitHub Desktop.
let _str = (function(){
const tag = document.createElement('span')
return {
propToAttr: (string) {
tag.dataset[string] = true
return tag.attributes[0].name.split(/^data-/)[1]
},
attrToProp(string) {
tag.setAttribute(`data-${string}`, true)
return Object.entries(tag.dataset)[0][0]
}
}
}())
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