Skip to content

Commit

Permalink
Add test cases & refine getSchemaName.
Browse files Browse the repository at this point in the history
  • Loading branch information
eyw520 committed Nov 22, 2024
1 parent 3c7babe commit 31b7b46
Show file tree
Hide file tree
Showing 11 changed files with 43,239 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { camelCase, upperFirst, lowerFirst } from "lodash-es";
import { camelCase, upperFirst } from "lodash-es";
import { replaceStartingNumber } from "./replaceStartingNumber";

function customCamelCase(input: string): string {
const tokens = input.split("_");
const processedTokens = tokens.map((token, index) => {
if (/^[a-zA-Z0-9]+$/.test(token)) {
return index === 0 ? lowerFirst(token) : upperFirst(token);
export function getGeneratedTypeName(breadcrumbs: string[], useOriginalSchemaIds: boolean): string {
const processedTokens = breadcrumbs.map((token) => {
if (/^[^a-zA-Z0-9]+$/.test(token)) {
return token;
} else {
return upperFirst(camelCase(token));
}
return token;
});
return processedTokens.join("");
}

export function getGeneratedTypeName(breadcrumbs: string[], useOriginalSchemaIds: boolean): string {
const camelCaseFn = useOriginalSchemaIds ? customCamelCase : camelCase;
const underscoreDelimited = breadcrumbs.join("_");
const name = upperFirst(camelCaseFn(underscoreDelimited));
const name = processedTokens.join("");

if (/^\d/.test(name)) {
return replaceStartingNumber(name) ?? name;
}
Expand Down
Loading

0 comments on commit 31b7b46

Please sign in to comment.