-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cz-commitlint,prompt): remove duplication in case conversion (…
…#2794) * refactor(cz-commitlint): remove duplication in case conversion The @commitlint/cz-commitlint was previously duplicating the case conversion logic also found in the @commitlint/ensure package. * refactor(prompt): remove duplication in case conversion The @commitlint/prompt package was previously duplicating the case conversion logic also found in the @commitlint/ensure package.
- Loading branch information
Showing
7 changed files
with
50 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {TargetCaseType} from '@commitlint/types'; | ||
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'; | ||
|
||
export default function toCase(input: string, target: TargetCaseType): string { | ||
switch (target) { | ||
case 'camel-case': | ||
return camelCase(input); | ||
case 'kebab-case': | ||
return kebabCase(input); | ||
case 'snake-case': | ||
return snakeCase(input); | ||
case 'pascal-case': | ||
return upperFirst(camelCase(input)); | ||
case 'start-case': | ||
return startCase(input); | ||
case 'upper-case': | ||
case 'uppercase': | ||
return input.toUpperCase(); | ||
case 'sentence-case': | ||
case 'sentencecase': | ||
return upperFirst(input); | ||
case 'lower-case': | ||
case 'lowercase': | ||
case 'lowerCase': // Backwards compat config-angular v4 | ||
return input.toLowerCase(); | ||
default: | ||
throw new TypeError(`to-case: Unknown target case "${target}"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters