From 1c57e672f4155430ca7cf9f56c6727fc8566046c Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Sat, 13 Apr 2024 23:19:58 -0700 Subject: [PATCH] cleanup --- src/index.ts | 8 +------- src/utils.ts | 5 +++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3bfa9d8..0ab272c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 = []; @@ -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, diff --git a/src/utils.ts b/src/utils.ts index 6b4d60d..b055bd0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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); +} \ No newline at end of file