Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature new UPPER/lower cases #621

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 13 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions test/types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});