From 8e5a32ad404e0f8a6537342fa4c7c0fe957b6758 Mon Sep 17 00:00:00 2001 From: Marco Maatz Date: Mon, 26 Sep 2022 14:10:52 +0200 Subject: [PATCH 1/2] adding basic upper/lower case functions --- README.md | 12 +++++++----- src/types.ts | 20 +++++++++++++++----- test/types.test.js | 10 ++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b3b8ded6..6a9e0835 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 + l = lower_case (Snake Case) + bl = lower_case (Basic) 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 + u = UPPER_CASE (Snake Case) + bu = UPPER_CASE (Basic) +--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..15b6c55c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -111,19 +111,23 @@ export function qNameJoin(schema: string | undefined, table: string | undefined) export declare type LangOption = "es5" | "es6" | "esm" | "ts"; /** "c" camelCase | - * "l" lower_case | + * "l" lower_case (Snake Case) | + * "bl" lower_case (Basic) | * "o" original (db) | * "p" PascalCase | - * "u" UPPER_CASE */ -export declare type CaseOption = "c" | "l" | "o" | "p" | "u"; + * "u" UPPER_CASE (Snake Case) | + * "bu" UPPER_CASE (Basic) */ +export declare type CaseOption = "c" | "l" | "o" | "p" | "u" | "bu" | "bl"; /** * "c" camelCase | * "k" kebab-case | - * "l" lower_case | + * "l" lower_case (Snake Case) | + * "bl" lower_case (Basic) | * "o" original (db) | * "p" PascalCase | - * "u" UPPER_CASE + * "u" UPPER_CASE (Snake Case) | + * "bu" UPPER_CASE (Basic) */ 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..eac45c8a 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 UPPER_CASE BASIC', function() { + const recasedString = recase('bu', 'relatedProduct'); + expect(recasedString).to.be.equal('RELATEDPRODUCT'); + }); + + it('recase lower_case basic', function() { + const recasedString = recase('bl', 'relatedProduct'); + expect(recasedString).to.be.equal('relatedproduct'); + }); }); From 20a202435e42d56193e3f9bd80db4982f52f277e Mon Sep 17 00:00:00 2001 From: Marco Maatz Date: Wed, 5 Oct 2022 09:35:15 +0200 Subject: [PATCH 2/2] description change --- README.md | 8 ++++---- src/types.ts | 16 ++++++++-------- test/types.test.js | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 6a9e0835..303a9eea 100644 --- a/README.md +++ b/README.md @@ -56,12 +56,12 @@ Options: -T, --skipTables Space-separated names of tables to skip [array] --caseModel, --cm Set case of model names: c|l|bl|o|p|u|bu c = camelCase - l = lower_case (Snake Case) - bl = lower_case (Basic) + l = lower_case + bl = lowercase o = original (default) p = PascalCase - u = UPPER_CASE (Snake Case) - bu = UPPER_CASE (Basic) + u = UPPER_CASE + 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 diff --git a/src/types.ts b/src/types.ts index 15b6c55c..c24e00e1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -111,23 +111,23 @@ export function qNameJoin(schema: string | undefined, table: string | undefined) export declare type LangOption = "es5" | "es6" | "esm" | "ts"; /** "c" camelCase | - * "l" lower_case (Snake Case) | - * "bl" lower_case (Basic) | + * "l" lower_case | + * "bl" lowercase | * "o" original (db) | * "p" PascalCase | - * "u" UPPER_CASE (Snake Case) | - * "bu" UPPER_CASE (Basic) */ + * "u" UPPER_CASE | + * "bu" UPPERCASE*/ export declare type CaseOption = "c" | "l" | "o" | "p" | "u" | "bu" | "bl"; /** * "c" camelCase | * "k" kebab-case | - * "l" lower_case (Snake Case) | - * "bl" lower_case (Basic) | + * "l" lower_case | + * "bl" lowercase | * "o" original (db) | * "p" PascalCase | - * "u" UPPER_CASE (Snake Case) | - * "bu" UPPER_CASE (Basic) + * "u" UPPER_CASE | + * "bu" UPPERCASE */ export declare type CaseFileOption = "k" | CaseOption; diff --git a/test/types.test.js b/test/types.test.js index eac45c8a..f3c8c7df 100644 --- a/test/types.test.js +++ b/test/types.test.js @@ -13,12 +13,12 @@ describe('sequelize-auto types', function() { expect(recasedString).to.be.equal('RELATED_PRODUCT'); }); - it('recase UPPER_CASE BASIC', function() { + it('recase UPPERCASE', function() { const recasedString = recase('bu', 'relatedProduct'); expect(recasedString).to.be.equal('RELATEDPRODUCT'); }); - it('recase lower_case basic', function() { + it('recase lowercase', function() { const recasedString = recase('bl', 'relatedProduct'); expect(recasedString).to.be.equal('relatedproduct'); });