Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Apr 14, 2024
1 parent 5b14573 commit 1c57e67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as t from "@babel/types";

import { defaultOptions, SchemaTSContext, type SchemaTSOptions } from "./context";
import type { JSONSchema, JSONSchemaProperty } from "./types";
import { toCamelCase, toPascalCase } from "./utils";
import { isValidIdentifier, toCamelCase, toPascalCase } from "./utils";

export function generateTypeScript(schema: JSONSchema, options?: SchemaTSOptions): string {
const interfaces = [];
Expand Down Expand Up @@ -67,12 +67,6 @@ function createInterfaceDeclaration(
return t.exportNamedDeclaration(interfaceDeclaration);
}


// Determine if the key is a valid JavaScript identifier
function isValidIdentifier(key: string) {
return /^[$A-Z_][0-9A-Z_$]*$/i.test(key) && !/^[0-9]+$/.test(key);
}

function createPropertySignature(
ctx: SchemaTSContext,
key: string,
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ export function toCamelCase(key: string) {
// Ensure the first character of the result is always lowercase
.replace(/^./, (c) => c.toLowerCase());
}

// Determine if the key is a valid JavaScript identifier
export function isValidIdentifier(key: string) {
return /^[$A-Z_][0-9A-Z_$]*$/i.test(key) && !/^[0-9]+$/.test(key);
}

0 comments on commit 1c57e67

Please sign in to comment.