Guest User

Untitled

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