diff --git a/@commitlint/ensure/src/case.ts b/@commitlint/ensure/src/case.ts index 13701efde5..6329aa8630 100644 --- a/@commitlint/ensure/src/case.ts +++ b/@commitlint/ensure/src/case.ts @@ -5,9 +5,7 @@ import upperFirst from 'lodash/upperFirst'; import startCase from 'lodash/startCase'; import {TargetCaseType} from '@commitlint/types'; -export default ensureCase; - -function ensureCase( +export default function ensureCase( raw: string = '', target: TargetCaseType = 'lowercase' ): boolean { @@ -26,7 +24,10 @@ function ensureCase( return transformed === input; } -function toCase(input: string, target: TargetCaseType): string { +/** + * @internal + */ +export function toCase(input: string, target: TargetCaseType): string { switch (target) { case 'camel-case': return camelCase(input); diff --git a/@commitlint/prompt/package.json b/@commitlint/prompt/package.json index baf8a6c2f4..a76fed9f56 100644 --- a/@commitlint/prompt/package.json +++ b/@commitlint/prompt/package.json @@ -45,8 +45,8 @@ "dependencies": { "@commitlint/load": "^11.0.0", "@commitlint/types": "^11.0.0", + "@commitlint/ensure": "^11.0.0", "chalk": "^4.0.0", - "lodash": "^4.17.19", "inquirer": "^6.5.2" }, "gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca" diff --git a/@commitlint/prompt/src/library/get-forced-case-fn.ts b/@commitlint/prompt/src/library/get-forced-case-fn.ts index 74b285afa8..d1227e1a7a 100644 --- a/@commitlint/prompt/src/library/get-forced-case-fn.ts +++ b/@commitlint/prompt/src/library/get-forced-case-fn.ts @@ -1,10 +1,7 @@ -import camelCase from 'lodash/camelCase'; -import kebabCase from 'lodash/kebabCase'; -import snakeCase from 'lodash/snakeCase'; -import upperFirst from 'lodash/upperFirst'; -import startCase from 'lodash/startCase'; import {RuleEntry} from './types'; import {ruleIsActive, ruleIsNotApplicable} from './utils'; +import {toCase} from '@commitlint/ensure/lib/case'; +import {TargetCaseType} from '@commitlint/types'; /** * Get forced case for rule @@ -26,29 +23,5 @@ export default function getForcedCaseFn( return noop; } - switch (target) { - case 'camel-case': - return (input: string) => camelCase(input); - case 'kebab-case': - return (input: string) => kebabCase(input); - case 'snake-case': - return (input: string) => snakeCase(input); - case 'pascal-case': - return (input: string) => upperFirst(camelCase(input)); - case 'start-case': - return (input: string) => startCase(input); - case 'upper-case': - case 'uppercase': - return (input: string) => input.toUpperCase(); - case 'sentence-case': - case 'sentencecase': - return (input: string) => - `${input.charAt(0).toUpperCase()}${input.substring(1).toLowerCase()}`; - case 'lower-case': - case 'lowercase': - case 'lowerCase': // Backwards compat config-angular v4 - return (input: string) => input.toLowerCase(); - default: - throw new TypeError(`Unknown target case "${target}"`); - } + return (input: string) => toCase(input, target as TargetCaseType); } diff --git a/@commitlint/prompt/tsconfig.json b/@commitlint/prompt/tsconfig.json index 119e645565..9b7a2ea8d8 100644 --- a/@commitlint/prompt/tsconfig.json +++ b/@commitlint/prompt/tsconfig.json @@ -7,5 +7,9 @@ }, "include": ["./src"], "exclude": ["./src/**/*.test.ts", "./lib/**/*"], - "references": [{"path": "../types"}] + "references": [ + {"path": "../types"}, + {"path": "../load"}, + {"path": "../ensure"} + ] }