Skip to content

Commit 26e1e7b

Browse files
committed
add option for camelCaseFn
1 parent c69b8df commit 26e1e7b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

packages/schema-typescript/src/context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface SchemaTSOptions {
1515
useSingleQuotes: boolean;
1616
camelCase?: boolean; // defaults to false
1717
camelCaseFn?: (str: string) => string; // optional function to convert keys to camelCase
18+
stripLeadingNonAlphabetChars?: boolean; // defaults to true, strips leading non-alphabet chars when camelCasing
1819
strictTypeSafety: boolean; // true uses { [k: string]: unknown; }, false uses any
1920
overrides?: SchemaDefinitionOverrides;
2021

@@ -72,6 +73,7 @@ export const defaultSchemaTSOptions: SchemaTSOptions = {
7273
useSingleQuotes: true,
7374
camelCase: false,
7475
camelCaseFn: null,
76+
stripLeadingNonAlphabetChars: false,
7577
strictTypeSafety: true,
7678
exclude: [],
7779
include: [],

packages/schema-typescript/src/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function createPropertySignature(
233233
required: string[],
234234
schema: JSONSchema
235235
): t.TSPropertySignature {
236-
let camelCaseFn: (str: string) => string = toCamelCase;
236+
let camelCaseFn: (str: string) => string = (str: string) => toCamelCase(str, ctx.options.stripLeadingNonAlphabetChars);
237237
if (ctx.options.camelCaseFn) camelCaseFn = ctx.options.camelCaseFn;
238238
const name = ctx.options.camelCase ? camelCaseFn(key) : key;
239239
const propType = getTypeForProp(ctx, prop, required, schema);

0 commit comments

Comments
 (0)