Last active
December 2, 2016 04:44
-
-
Save Swivelgames/19b382f11aea5354cc67aa316955fbaa to your computer and use it in GitHub Desktop.
camelCase: Like camelCase npm package, formats hyphen, period, underscore, or space separated strings in camelCase.
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
| const camelCase = (...args) => { | |
| let str = args.join("-") | |
| .replace(/[ _.-]+[A-Za-z]{1}/g, | |
| (m) => m.replace(/[^A-Za-z]/g, '').toUpperCase() | |
| ).replace(/[ _.-]/g, ''); | |
| return str[0].toLowerCase() + str.substr(1); | |
| } | |
| var str = "__foo___bar____---"; | |
| camelCase(str); // fooBar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment