Fully renamed and updated everything, tagged, built
This commit is contained in:
14
snippets/toCamelCase.md
Normal file
14
snippets/toCamelCase.md
Normal file
@ -0,0 +1,14 @@
|
||||
### toCamelCase
|
||||
|
||||
Converts a string to camelcase.
|
||||
|
||||
Use `replace()` to remove underscores, hyphens and spaces and convert words to camelcase.
|
||||
|
||||
```js
|
||||
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'
|
||||
```
|
||||
Reference in New Issue
Block a user