Created
March 20, 2020 09:25
-
-
Save darkmavis1980/7700c0d41398fd3b803ef513d593d229 to your computer and use it in GitHub Desktop.
Kebab case to camel case string conversion
This file contains 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
/** | |
* @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