Skip to content

Commit

Permalink
Merge pull request #28 from barnuri/ts-fix-enum
Browse files Browse the repository at this point in the history
ts-fix-enum
  • Loading branch information
barnuri committed May 16, 2024
2 parents 25ba328 + 09c8d1d commit b6df297
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/generators/TypescriptGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ ${objectInput.properties
const modelFile = join(this.modelsFolder, this.getFileName(enumInput) + this.getFileExtension(true));
const specialChars = ['-', ' ', '!'];
const specialKeywords = ['in', 'public', 'private', 'readonly'];
const shouldWrapName = (name: string) => {
if (specialChars.filter(x => name.includes(x)).length > 0) { return true; }
if (specialKeywords.filter(x => name === x).length > 0) { return true; }
if (!isNaN(parseFloat(name))) { return true; }
return false;
const fixName = (name: string) => {
if (specialChars.filter(x => name.includes(x)).length > 0) { return `"${name}"`; }
if (specialKeywords.filter(x => name === x).length > 0) { return `"${name}"`; }
if (!isNaN(parseFloat(name))) { return `Num${name}`; }
return name;
};
const fixName = (name: string) => shouldWrapName(name) ? `"${name}"` : name;
const modelFileContent = `
export enum ${this.getFileName(enumInput)} {
${Object.keys(enumVals)
Expand Down

0 comments on commit b6df297

Please sign in to comment.