-
-
Save bkardell/cff42ab863dbd5cbb5d28d9309eab712 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
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] | |
} | |
} | |
}()) |
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