File tree Expand file tree Collapse file tree 2 files changed +1
-30
lines changed
projects/common/src/utilities/formatters/string Expand file tree Collapse file tree 2 files changed +1
-30
lines changed Original file line number Diff line number Diff line change 1- import {
2- displayString ,
3- getStringsFromCommaSeparatedList ,
4- titleCaseFromKebabCase ,
5- titleCaseFromSnakeCase
6- } from './string-formatter' ;
1+ import { displayString , getStringsFromCommaSeparatedList } from './string-formatter' ;
72
83describe ( 'String formatter' , ( ) => {
9- test ( 'can convert from kebab case to title case' , ( ) => {
10- expect ( titleCaseFromKebabCase ( 'my-kebab-case' ) ) . toBe ( 'My Kebab Case' ) ;
11- expect ( titleCaseFromKebabCase ( 'single' ) ) . toBe ( 'Single' ) ;
12- expect ( titleCaseFromKebabCase ( '' ) ) . toBe ( '' ) ;
13- } ) ;
14-
15- test ( 'can convert from snake case to title case' , ( ) => {
16- expect ( titleCaseFromSnakeCase ( 'my_snake_case' ) ) . toBe ( 'My Snake Case' ) ;
17- expect ( titleCaseFromKebabCase ( 'single' ) ) . toBe ( 'Single' ) ;
18- expect ( titleCaseFromKebabCase ( '' ) ) . toBe ( '' ) ;
19- } ) ;
20-
214 test ( 'can convert to display string' , ( ) => {
225 // tslint:disable-next-line: no-null-keyword
236 expect ( displayString ( null ) ) . toBe ( '-' ) ;
Original file line number Diff line number Diff line change 1- export const titleCaseFromKebabCase = ( kebabCaseString : string ) : string =>
2- kebabCaseString
3- . split ( '-' )
4- . map ( str => ( str . length === 0 ? str : str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) ) )
5- . join ( ' ' ) ;
6-
7- export const titleCaseFromSnakeCase = ( snakeCaseString : string ) : string =>
8- snakeCaseString
9- . split ( '_' )
10- . map ( str => ( str . length === 0 ? str : str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) ) )
11- . join ( ' ' ) ;
12-
131export const displayString = ( provided ?: unknown ) : string => {
142 if ( provided === null ) {
153 return '-' ;
You can’t perform that action at this time.
0 commit comments