Skip to content

Instantly share code, notes, and snippets.

@yojona
Created March 26, 2019 21:41
Show Gist options
  • Save yojona/3ad63ce60e7c1d72a00f0568bd26ecca to your computer and use it in GitHub Desktop.
Save yojona/3ad63ce60e7c1d72a00f0568bd26ecca to your computer and use it in GitHub Desktop.
const toCamelCase = string => {
return string.replace(/^([A-Z])|[\s-_](\w)/g, (match, p1, p2, offset) => {
if (p2) return p2.toUpperCase();
return p1.toLowerCase();
});
}
console.log(toCamelCase("Hola perro"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment