Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const toCamelCase = str =>
- str.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2, offset) => p2 ? p2.toUpperCase() : p1.toLowerCase());
- // toCamelCase("some_database_field_name") -> 'someDatabaseFieldName'
- // toCamelCase("Some label that needs to be camelized") -> 'someLabelThatNeedsToBeCamelized'
- // toCamelCase("some-javascript-property") -> 'someJavascriptProperty'
- // toCamelCase("some-mixed_string with spaces_underscores-and-hyphens") -> 'someMixedStringWithSpacesUnderscoresAndHyphens'
Add Comment
Please, Sign In to add comment