Created
June 17, 2022 10:24
-
-
Save bgoonz/723cbfc17a841b3478dfa70e26543d66 to your computer and use it in GitHub Desktop.
CamelCase.tsx
This file contains hidden or 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 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