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' ;
7
2
8
3
describe ( '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
-
21
4
test ( 'can convert to display string' , ( ) => {
22
5
// tslint:disable-next-line: no-null-keyword
23
6
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
-
13
1
export const displayString = ( provided ?: unknown ) : string => {
14
2
if ( provided === null ) {
15
3
return '-' ;
You can’t perform that action at this time.
0 commit comments