From cada91e7c4aa71902a5639c0c0fd3ee2b4fd257e Mon Sep 17 00:00:00 2001 From: Ewout Stortenbeker Date: Mon, 13 Feb 2023 20:46:52 +0100 Subject: [PATCH 1/2] Improve ts style schema object parser: - Allow ; as property delimiter - Allow trailing ; or , --- src/schema.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/schema.ts b/src/schema.ts index e732e46..d44edd3 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -112,8 +112,11 @@ function parse(definition: string) { const types = readTypes(); type.children.push({ name: prop.name, optional: prop.optional, wildcard: prop.wildcard, types }); consumeSpaces(); + if (definition[pos] === ';' || definition[pos] === ',') { + consumeCharacter(definition[pos]); + consumeSpaces(); + } if (definition[pos] === '}') { break; } - consumeCharacter(','); } consumeCharacter('}'); } From 6fc802bdfa6be31968f85558006f481131658f2e Mon Sep 17 00:00:00 2001 From: Ewout Stortenbeker Date: Mon, 13 Feb 2023 20:49:15 +0100 Subject: [PATCH 2/2] use ; as type delimiter --- src/schema.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/schema.ts b/src/schema.ts index d44edd3..45ded8f 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1,18 +1,18 @@ export interface IType { - typeOf: string, // typeof + typeOf: string; // typeof // eslint-disable-next-line @typescript-eslint/ban-types - instanceOf?: Function, // eg: instanceof 'Array' - value?:string|number|boolean|bigint|null, - genericTypes?: IType[], - children?: IProperty[], - matches?: RegExp // NEW: enforces regular expression checks on values + instanceOf?: Function; // eg: instanceof 'Array' + value?: string|number|boolean|bigint|null; + genericTypes?: IType[]; + children?: IProperty[]; + matches?: RegExp; // enforces regular expression checks on values } export interface IProperty { - name: string, - optional: boolean, - wildcard: boolean, - types: IType[] + name: string; + optional: boolean; + wildcard: boolean; + types: IType[]; } // parses a typestring, creates checker functions