File tree 4 files changed +14
-36
lines changed
4 files changed +14
-36
lines changed Original file line number Diff line number Diff line change @@ -5,9 +5,7 @@ import upperFirst from 'lodash/upperFirst';
5
5
import startCase from 'lodash/startCase' ;
6
6
import { TargetCaseType } from '@commitlint/types' ;
7
7
8
- export default ensureCase ;
9
-
10
- function ensureCase (
8
+ export default function ensureCase (
11
9
raw : string = '' ,
12
10
target : TargetCaseType = 'lowercase'
13
11
) : boolean {
@@ -26,7 +24,10 @@ function ensureCase(
26
24
return transformed === input ;
27
25
}
28
26
29
- function toCase ( input : string , target : TargetCaseType ) : string {
27
+ /**
28
+ * @internal
29
+ */
30
+ export function toCase ( input : string , target : TargetCaseType ) : string {
30
31
switch ( target ) {
31
32
case 'camel-case' :
32
33
return camelCase ( input ) ;
Original file line number Diff line number Diff line change 45
45
"dependencies" : {
46
46
"@commitlint/load" : " ^11.0.0" ,
47
47
"@commitlint/types" : " ^11.0.0" ,
48
+ "@commitlint/ensure" : " ^11.0.0" ,
48
49
"chalk" : " ^4.0.0" ,
49
- "lodash" : " ^4.17.19" ,
50
50
"inquirer" : " ^6.5.2"
51
51
},
52
52
"gitHead" : " cb565dfcca3128380b9b3dc274aedbcae34ce5ca"
Original file line number Diff line number Diff line change 1
- import camelCase from 'lodash/camelCase' ;
2
- import kebabCase from 'lodash/kebabCase' ;
3
- import snakeCase from 'lodash/snakeCase' ;
4
- import upperFirst from 'lodash/upperFirst' ;
5
- import startCase from 'lodash/startCase' ;
6
1
import { RuleEntry } from './types' ;
7
2
import { ruleIsActive , ruleIsNotApplicable } from './utils' ;
3
+ import { toCase } from '@commitlint/ensure/lib/case' ;
4
+ import { TargetCaseType } from '@commitlint/types' ;
8
5
9
6
/**
10
7
* Get forced case for rule
@@ -26,29 +23,5 @@ export default function getForcedCaseFn(
26
23
return noop ;
27
24
}
28
25
29
- switch ( target ) {
30
- case 'camel-case' :
31
- return ( input : string ) => camelCase ( input ) ;
32
- case 'kebab-case' :
33
- return ( input : string ) => kebabCase ( input ) ;
34
- case 'snake-case' :
35
- return ( input : string ) => snakeCase ( input ) ;
36
- case 'pascal-case' :
37
- return ( input : string ) => upperFirst ( camelCase ( input ) ) ;
38
- case 'start-case' :
39
- return ( input : string ) => startCase ( input ) ;
40
- case 'upper-case' :
41
- case 'uppercase' :
42
- return ( input : string ) => input . toUpperCase ( ) ;
43
- case 'sentence-case' :
44
- case 'sentencecase' :
45
- return ( input : string ) =>
46
- `${ input . charAt ( 0 ) . toUpperCase ( ) } ${ input . substring ( 1 ) . toLowerCase ( ) } ` ;
47
- case 'lower-case' :
48
- case 'lowercase' :
49
- case 'lowerCase' : // Backwards compat config-angular v4
50
- return ( input : string ) => input . toLowerCase ( ) ;
51
- default :
52
- throw new TypeError ( `Unknown target case "${ target } "` ) ;
53
- }
26
+ return ( input : string ) => toCase ( input , target as TargetCaseType ) ;
54
27
}
Original file line number Diff line number Diff line change 7
7
},
8
8
"include" : [" ./src" ],
9
9
"exclude" : [" ./src/**/*.test.ts" , " ./lib/**/*" ],
10
- "references" : [{"path" : " ../types" }]
10
+ "references" : [
11
+ {"path" : " ../types" },
12
+ {"path" : " ../load" },
13
+ {"path" : " ../ensure" }
14
+ ]
11
15
}
You can’t perform that action at this time.
0 commit comments