Skip to content

Instantly share code, notes, and snippets.

@darkmavis1980
Created March 20, 2020 09:25
Show Gist options
  • Save darkmavis1980/7700c0d41398fd3b803ef513d593d229 to your computer and use it in GitHub Desktop.
Save darkmavis1980/7700c0d41398fd3b803ef513d593d229 to your computer and use it in GitHub Desktop.
Kebab case to camel case string conversion
/**
* @description Transform a kebab case string into a Camel Case
* @param {string} string Source string
*
* @example
* // returns thisIsMyString
* kebabToCamelCase('this-is-my-string');
* @returns {string}
*/
export function kebabToCamelCase(string) {
if (typeof string !== 'string') {
return string;
}
return string.replace(
/([-_][a-z])/g,
group => group.toUpperCase()
.replace('-', '')
.replace('_', '')
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment