Skip to content

Instantly share code, notes, and snippets.

@kahl-dev
Created September 8, 2017 11:47
Show Gist options
  • Save kahl-dev/146c920a96addbe0eb590d9f2a38de0b to your computer and use it in GitHub Desktop.
Save kahl-dev/146c920a96addbe0eb590d9f2a38de0b to your computer and use it in GitHub Desktop.
Handle dataset
function hyphenToCamelCase(string) {
return string.replace('data-', '').replace(/-([a-z])/g, string => {
return string[1].toUpperCase();
});
}
function camelCaseToHyphen(string) {
return `data-${string.replace(/([A-Z])/g, string => {
return `-${string.toLowerCase()}`;
})}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment