File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed
Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ export function normalizeToKebabOrSnakeCase(str: string) {
99 const STRING_DASHERIZE_REGEXP = / \s / g;
1010 const STRING_DECAMELIZE_REGEXP = / ( [ a - z \d ] ) ( [ A - Z ] ) / g;
1111 return str
12- . replace ( STRING_DECAMELIZE_REGEXP , '$1-$2' )
13- . toLowerCase ( )
14- . replace ( STRING_DASHERIZE_REGEXP , '-' ) ;
12+ ?. trim ( )
13+ ?. replace ( STRING_DECAMELIZE_REGEXP , '$1-$2' )
14+ ?. toLowerCase ( )
15+ ?. replace ( STRING_DASHERIZE_REGEXP , '-' ) ;
1516}
Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ export * from './module.finder';
66export * from './name.parser' ;
77export * from './path.solver' ;
88export * from './source-root.helpers' ;
9+ export * from './formatting' ;
Original file line number Diff line number Diff line change 1+ import { normalizeToKebabOrSnakeCase } from '../../src/utils' ;
2+
3+ describe ( 'normalizeToKebabOrSnakeCase' , ( ) => {
4+ it ( 'should convert camelCase to kebab-case' , ( ) => {
5+ const input = 'camelCaseString' ;
6+ const output = normalizeToKebabOrSnakeCase ( input ) ;
7+ expect ( output ) . toBe ( 'camel-case-string' ) ;
8+ } ) ;
9+
10+ it ( 'should replace spaces with dashes' , ( ) => {
11+ const input = 'string with spaces' ;
12+ const output = normalizeToKebabOrSnakeCase ( input ) ;
13+ expect ( output ) . toBe ( 'string-with-spaces' ) ;
14+ } ) ;
15+
16+ it ( 'should keep underscores' , ( ) => {
17+ const input = 'string_with_underscores' ;
18+ const output = normalizeToKebabOrSnakeCase ( input ) ;
19+ expect ( output ) . toBe ( 'string_with_underscores' ) ;
20+ } ) ;
21+
22+ it ( 'should handle empty string' , ( ) => {
23+ const input = '' ;
24+ const output = normalizeToKebabOrSnakeCase ( input ) ;
25+ expect ( output ) . toBe ( '' ) ;
26+ } ) ;
27+
28+ it ( 'should handle strings with leading/trailing spaces' , ( ) => {
29+ const input = ' leading and trailing spaces ' ;
30+ const output = normalizeToKebabOrSnakeCase ( input ) ;
31+ expect ( output ) . toBe ( 'leading-and-trailing-spaces' ) ;
32+ } ) ;
33+ } ) ;
You can’t perform that action at this time.
0 commit comments