Update convert-string-to-camelcase.md

This commit is contained in:
Alexander Sokolov
2017-12-16 22:09:06 +03:00
committed by GitHub
parent e37de0ff2a
commit f14bfd293e

View File

@ -5,8 +5,8 @@ Use `replace()` to remove underscores, hyphens and spaces and convert words to c
```js
const toCamelCase = str =>
str.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2, offset) => p2 ? p2.toUpperCase() : p1.toLowerCase());
// camelize("some_database_field_name") -> 'someDatabaseFieldName'
// camelize("Some label that needs to be camelized") -> 'someLabelThatNeedsToBeCamelized'
// camelize("some-javascript-property") -> 'someJavascriptProperty'
// camelize("some-mixed_string with spaces_underscores-and-hyphens") -> 'someMixedStringWithSpacesUnderscoresAndHyphens'
// 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'
```