Merge pull request #36 from appy-one/improvement/ts-style-schema-object-parser

Improvement: TS style schema object parser
This commit is contained in:
Ewout Stortenbeker 2023-02-13 20:53:10 +01:00 committed by GitHub
commit fbd28fac36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
@ -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('}');
}