Skip to content

Instantly share code, notes, and snippets.

@michael-lynch
Created September 12, 2022 21:09
Show Gist options
  • Save michael-lynch/255f55f6ab5af0d44c8e2b8a130b9ac5 to your computer and use it in GitHub Desktop.
Save michael-lynch/255f55f6ab5af0d44c8e2b8a130b9ac5 to your computer and use it in GitHub Desktop.
Convert string to camelCase
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