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', () => {
116116 expect ( filterSensitiveInfoFromRepositoryUrl ( input ) ) . toBe ( expected ) ;
117117 } ) ;
118118 } ) ;
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+ } ) ;
119135} ) ;
Original file line number Diff line number Diff line change @@ -60,5 +60,12 @@ export const filterSensitiveInfoFromRepositoryUrl = (repositoryUrl: string = '')
6060 }
6161} ;
6262
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+
6370let index = 0 ;
6471export const getUniqueId = ( ) => `${ Date . now ( ) } .${ performance . now ( ) } .${ ++ index } ` ;
You can’t perform that action at this time.
0 commit comments