32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
|
|
type SchemaType = 'string' | 'number' | 'boolean';
|
||
|
|
interface PrimitiveSchema {
|
||
|
|
type: SchemaType;
|
||
|
|
}
|
||
|
|
interface TupleSchema {
|
||
|
|
type: 'tuple';
|
||
|
|
elements: Schema[];
|
||
|
|
}
|
||
|
|
interface ArraySchema {
|
||
|
|
type: 'array';
|
||
|
|
element: Schema;
|
||
|
|
}
|
||
|
|
type Schema = PrimitiveSchema | TupleSchema | ArraySchema;
|
||
|
|
interface ParsedSchema {
|
||
|
|
schema: Schema;
|
||
|
|
validator: (value: unknown) => boolean;
|
||
|
|
parse: (valueString: string) => unknown;
|
||
|
|
}
|
||
|
|
|
||
|
|
declare class ParseError extends Error {
|
||
|
|
position?: number | undefined;
|
||
|
|
constructor(message: string, position?: number | undefined);
|
||
|
|
}
|
||
|
|
declare function parseSchema(schemaString: string): Schema;
|
||
|
|
|
||
|
|
declare function parseValue(schema: Schema, valueString: string): unknown;
|
||
|
|
declare function createValidator(schema: Schema): (value: unknown) => boolean;
|
||
|
|
|
||
|
|
declare function defineSchema(schemaString: string): ParsedSchema;
|
||
|
|
|
||
|
|
export { type ArraySchema, ParseError, type ParsedSchema, type PrimitiveSchema, type Schema, type TupleSchema, createValidator, defineSchema, parseSchema, parseValue };
|