Merge pull request #855 from ccjmne/add-totitlecase
Add toTitleCase snippet and update tag_database accordingly
This commit is contained in:
19
snippets/toTitleCase.md
Normal file
19
snippets/toTitleCase.md
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
### toTitleCase
|
||||||
|
|
||||||
|
Converts a string to title case.
|
||||||
|
|
||||||
|
Break the string into words, using a regexp, and combine them capitalizing the first letter of each word and adding a whitespace between them.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const toTitleCase = str => str
|
||||||
|
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||||
|
.map(x => x.charAt(0).toUpperCase() + x.slice(1))
|
||||||
|
.join(' ');
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
toTitleCase('some_database_field_name'); // 'Some Database Field Name'
|
||||||
|
toTitleCase('Some label that needs to be title-cased'); // 'Some Label That Needs To Be Title Cased'
|
||||||
|
toTitleCase('some-package-name'); // 'Some Package Name'
|
||||||
|
toTitleCase('some-mixed_string with spaces_underscores-and-hyphens'); // 'Some Mixed String With Spaces Underscores And Hyphens'
|
||||||
|
```
|
||||||
@ -301,6 +301,7 @@ tomorrow:date,intermediate
|
|||||||
toOrdinalSuffix:utility,math,intermediate
|
toOrdinalSuffix:utility,math,intermediate
|
||||||
toSafeInteger:math,beginner
|
toSafeInteger:math,beginner
|
||||||
toSnakeCase:string,regexp,intermediate
|
toSnakeCase:string,regexp,intermediate
|
||||||
|
toTitleCase:string,regepx,intermediate
|
||||||
transform:object,array,intermediate
|
transform:object,array,intermediate
|
||||||
triggerEvent:browser,event,intermediate
|
triggerEvent:browser,event,intermediate
|
||||||
truncateString:string,beginner
|
truncateString:string,beginner
|
||||||
|
|||||||
Reference in New Issue
Block a user