Skip to content

Commit

Permalink
fix(types): fix generated types for number prefixed identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Jul 18, 2024
1 parent bbabaca commit fc4b703
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}"
`);
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down

0 comments on commit fc4b703

Please sign in to comment.