From fc4b7038458aab2d7359f8edc8d386472534705f Mon Sep 17 00:00:00 2001 From: Nicolas Froidure Date: Thu, 18 Jul 2024 15:46:24 +0200 Subject: [PATCH] fix(types): fix generated types for number prefixed identifier --- src/index.test.ts | 24 ++++++++++++------------ src/index.ts | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index fb4e867..4e7c596 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -376,21 +376,21 @@ describe('generateJSONSchemaTypes()', () => { }; expect( - toSource( - await generateJSONSchemaTypes(schema, { - brandedTypes: [], - generateRealEnums: true, - tuplesFromFixedArraysLengthLimit: 5, - exportNamespaces: true, - }), - ), - ).toMatchInlineSnapshot(` + toSource( + await generateJSONSchemaTypes(schema, { + brandedTypes: [], + generateRealEnums: true, + tuplesFromFixedArraysLengthLimit: 5, + exportNamespaces: true + }) + ) +).toMatchInlineSnapshot(` "export type Main = Enums.Limit; export namespace Enums { export enum Limit { - _0M = "1m", - _0D = "1d", - _0W = "1w" + _1M = "1m", + _1D = "1d", + _1W = "1w" } }" `); diff --git a/src/index.ts b/src/index.ts index 5f4bd4e..b87cef4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,7 +53,7 @@ export function buildIdentifier(part: string): string { (_: unknown, $1: string, $2: string) => $1 + $2.toUpperCase(), ) .replace(/[^a-z0-9]/gi, '') - .replace(/^[0-9]/, (_: unknown, $1: string) => '_' + $1); + .replace(/^([0-9])/, (_: unknown, $1: string) => '_' + $1); return identifier || 'Unknown'; }