Created
September 12, 2022 21:09
-
-
Save michael-lynch/255f55f6ab5af0d44c8e2b8a130b9ac5 to your computer and use it in GitHub Desktop.
Convert string to camelCase
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
export const toCamelCase = string => { | |
if (!string) { | |
return ''; | |
} | |
let newString = string.toLowerCase(); | |
newString = newString.replace(/ /g, '_').toLowerCase(); | |
newString = newString.replace(/_([a-z])/g, g => { | |
return g[1].toUpperCase(); | |
}); | |
return newString; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment