Skip to content

Instantly share code, notes, and snippets.

@bgoonz
Created June 17, 2022 10:24
Show Gist options
  • Save bgoonz/723cbfc17a841b3478dfa70e26543d66 to your computer and use it in GitHub Desktop.
Save bgoonz/723cbfc17a841b3478dfa70e26543d66 to your computer and use it in GitHub Desktop.
CamelCase.tsx
export default function toCamelCase(string: string) {
const result = string
.toLowerCase()
.trim()
.split(/[ -_]/g)
.map(word => word.replace(word[0], word[0].toString().toUpperCase()))
.join('');
return result.replace(result[0], result[0].toLowerCase());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment