diff --git a/README.md b/README.md index b3b8ded6..303a9eea 100644 --- a/README.md +++ b/README.md @@ -54,14 +54,16 @@ Options: --indentation Number of spaces to indent [number] -t, --tables Space-separated names of tables to import [array] -T, --skipTables Space-separated names of tables to skip [array] ---caseModel, --cm Set case of model names: c|l|o|p|u +--caseModel, --cm Set case of model names: c|l|bl|o|p|u|bu c = camelCase l = lower_case + bl = lowercase o = original (default) p = PascalCase u = UPPER_CASE ---caseProp, --cp Set case of property names: c|l|o|p|u ---caseFile, --cf Set case of file names: c|l|o|p|u|k + bu = UPPERCASE +--caseProp, --cp Set case of property names: c|l|bl|o|p|u|bu +--caseFile, --cf Set case of file names: c|l|bl|o|p|u|bu|k k = kebab-case --noAlias Avoid creating alias `as` property in relations [boolean] diff --git a/src/types.ts b/src/types.ts index cb3d52a0..c24e00e1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -112,18 +112,22 @@ export declare type LangOption = "es5" | "es6" | "esm" | "ts"; /** "c" camelCase | * "l" lower_case | + * "bl" lowercase | * "o" original (db) | * "p" PascalCase | - * "u" UPPER_CASE */ -export declare type CaseOption = "c" | "l" | "o" | "p" | "u"; + * "u" UPPER_CASE | + * "bu" UPPERCASE*/ +export declare type CaseOption = "c" | "l" | "o" | "p" | "u" | "bu" | "bl"; /** * "c" camelCase | * "k" kebab-case | * "l" lower_case | + * "bl" lowercase | * "o" original (db) | * "p" PascalCase | - * "u" UPPER_CASE + * "u" UPPER_CASE | + * "bu" UPPERCASE */ export declare type CaseFileOption = "k" | CaseOption; @@ -221,12 +225,18 @@ export function recase(opt: CaseOption | CaseFileOption | undefined, val: string if (opt === 'l') { return _.snakeCase(val); } + if (opt === 'bl') { + return String(val).toLowerCase(); + } if (opt === 'p') { return _.upperFirst(_.camelCase(val)); } if (opt === 'u') { return _.snakeCase(val).toUpperCase(); } + if (opt === 'bu') { + return String(val).toUpperCase(); + } return val; } diff --git a/test/types.test.js b/test/types.test.js index 762ef68e..f3c8c7df 100644 --- a/test/types.test.js +++ b/test/types.test.js @@ -12,4 +12,14 @@ describe('sequelize-auto types', function() { const recasedString = recase('u', 'related_product'); expect(recasedString).to.be.equal('RELATED_PRODUCT'); }); + + it('recase UPPERCASE', function() { + const recasedString = recase('bu', 'relatedProduct'); + expect(recasedString).to.be.equal('RELATEDPRODUCT'); + }); + + it('recase lowercase', function() { + const recasedString = recase('bl', 'relatedProduct'); + expect(recasedString).to.be.equal('relatedproduct'); + }); });