File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
packages/core/src/helpers Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -116,4 +116,20 @@ describe('Strings Helpers', () => {
116
116
expect ( filterSensitiveInfoFromRepositoryUrl ( input ) ) . toBe ( expected ) ;
117
117
} ) ;
118
118
} ) ;
119
+
120
+ describe ( 'capitalize' , ( ) => {
121
+ test . each ( [
122
+ [ 'hello world' , 'Hello World' ] ,
123
+ [ 'hello' , 'Hello' ] ,
124
+ [ 'HELLO' , 'Hello' ] ,
125
+ [ 'hELLO' , 'Hello' ] ,
126
+ [ 'hELLO wORLD' , 'Hello World' ] ,
127
+ [ 'hELLO wORLD!' , 'Hello World!' ] ,
128
+ [ 'hELLO wORLD! 123' , 'Hello World! 123' ] ,
129
+ [ '' , '' ] ,
130
+ ] ) ( 'Should capitalize "%s" => "%s"' , async ( str , expected ) => {
131
+ const { capitalize } = await import ( '@dd/core/helpers/strings' ) ;
132
+ expect ( capitalize ( str ) ) . toBe ( expected ) ;
133
+ } ) ;
134
+ } ) ;
119
135
} ) ;
Original file line number Diff line number Diff line change @@ -60,5 +60,12 @@ export const filterSensitiveInfoFromRepositoryUrl = (repositoryUrl: string = '')
60
60
}
61
61
} ;
62
62
63
+ // Capitalize the first letter of each word in a string.
64
+ export const capitalize = ( str : string ) =>
65
+ str
66
+ . split ( ' ' )
67
+ . map ( ( st ) => st . charAt ( 0 ) . toUpperCase ( ) + st . slice ( 1 ) . toLowerCase ( ) )
68
+ . join ( ' ' ) ;
69
+
63
70
let index = 0 ;
64
71
export const getUniqueId = ( ) => `${ Date . now ( ) } .${ performance . now ( ) } .${ ++ index } ` ;
You can’t perform that action at this time.
0 commit comments