File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11export const dasherize = ( str : unknown ) : string =>
2- String ( str )
2+ String ( typeof str === 'symbol' ? str . description : str )
33 . replace ( / ( [ A - Z ] ( $ | [ a - z ] ) ) / g, '-$1' )
44 . replace ( / - - / g, '-' )
55 . replace ( / ^ - | - $ / , '' )
66 . toLowerCase ( )
7+
8+ export const mustDasherize = ( str : unknown , type = 'property' ) : string => {
9+ const dashed = dasherize ( str )
10+ if ( ! dashed . includes ( '-' ) ) {
11+ throw new DOMException ( `${ type } : ${ String ( str ) } is not a valid ${ type } name` , 'SyntaxError' )
12+ }
13+ return dashed
14+ }
Original file line number Diff line number Diff line change @@ -8,10 +8,11 @@ describe('dasherize', () => {
88 [ 'FooBar' , 'foo-bar' ] ,
99 [ 'autofocusWhenReady' , 'autofocus-when-ready' ] ,
1010 [ 'URLBar' , 'url-bar' ] ,
11- [ 'ClipX' , 'clip-x' ]
11+ [ 'ClipX' , 'clip-x' ] ,
12+ [ Symbol ( 'helloWorld' ) , 'hello-world' ]
1213 ]
1314
1415 tests . map ( ( [ input , output ] ) =>
15- it ( `transforms ${ input } to ${ output } ` , ( ) => expect ( dasherize ( input ) ) . to . equal ( output ) )
16+ it ( `transforms ${ String ( input ) } to ${ output } ` , ( ) => expect ( dasherize ( input ) ) . to . equal ( output ) )
1617 )
1718} )
You can’t perform that action at this time.
0 commit comments