Skip to content

Commit 5028056

Browse files
committed
chore(typescript): Use tsutils isValidIdentifier
1 parent 6c16829 commit 5028056

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

plugins/typescript/src/core/schemaToEnumDeclaration.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,10 @@
11
import { pascal } from "case";
22
import { SchemaObject } from "openapi3-ts/oas30";
33
import ts, { factory as f } from "typescript";
4+
import { isValidIdentifier } from "tsutils";
45
import { convertNumberToWord } from "../utils/getEnumProperties";
56
import { Context, getJSDocComment } from "./schemaToTypeAliasDeclaration";
67

7-
/**
8-
* Function to check if a string is a valid TypeScript identifier
9-
*
10-
* @param name Name to check
11-
*/
12-
function isValidIdentifier(name: string): boolean {
13-
if (name.length === 0) {
14-
return false;
15-
}
16-
17-
const firstChar = name.charCodeAt(0);
18-
if (!ts.isIdentifierStart(firstChar, ts.ScriptTarget.Latest)) {
19-
return false;
20-
}
21-
22-
for (let i = 1; i < name.length; i++) {
23-
if (!ts.isIdentifierPart(name.charCodeAt(i), ts.ScriptTarget.Latest)) {
24-
return false;
25-
}
26-
}
27-
28-
return true;
29-
}
30-
318
/**
329
* Add Enum support when transforming an OpenAPI Schema Object to Typescript Nodes.
3310
*

0 commit comments

Comments
 (0)