funval
Version:
A minimalist library for data validation using functions interfaces.
25 lines (24 loc) • 2.79 kB
TypeScript
import { SchemaValidator, SyncFunctionValidator, ValidatorOutput } from '../Schema';
import { Input } from '../Type';
import { FunctionType } from '../utils';
import { ErrorLike } from '../Error';
declare type TypeOfType<T> = T extends 'string' ? string : T extends 'number' ? number : T extends 'object' ? object : T extends 'boolean' ? boolean : T extends 'symbol' ? symbol : T extends 'bigint' ? bigint : T extends 'undefined' ? undefined : never;
export declare function Maybe<T>(schema: T, error?: ErrorLike): SchemaValidator<T | undefined, [Input<T>?]>;
export declare function Optional<T>(schema: T, error?: ErrorLike): SchemaValidator<T | undefined, [(Input<T> | null)?]>;
export declare function Default<T, V>(schema: T, defaultValue: V, error?: ErrorLike): FunctionType<ValidatorOutput<T> | V, [Input<T>?]>;
export declare function Required<T>(schema: T, error?: ErrorLike): SchemaValidator<T, [Exclude<Input<T>, undefined>]>;
export declare function Truthy<T>(input: T, error?: ErrorLike): T;
export declare function Or<A>(a: A): SchemaValidator<A, [Input<A>]>;
export declare function Or<A, B>(a: A, b: B): SchemaValidator<A | B, [Input<A> | Input<B>]>;
export declare function Or<A, B, C>(a: A, b: B, c: C): SchemaValidator<A | B | C, [Input<A> | Input<B> | Input<C>]>;
export declare function Or<A, B, C, D>(a: A, b: B, c: C, d: D): SchemaValidator<A | B | C | D, [Input<A> | Input<B> | Input<C> | Input<D>]>;
export declare function Or<A, B, C, D, E>(a: A, b: B, c: C, d: D, e: E): SchemaValidator<A | B | C | D | E, [Input<A> | Input<B> | Input<C> | Input<D> | Input<E>]>;
export declare function Or<A, B, C, D, E, F>(a: A, b: B, c: C, d: D, e: E, f: F): SchemaValidator<A | B | C | D | E | F, [Input<A> | Input<B> | Input<C> | Input<D> | Input<E> | Input<F>]>;
export declare function Or<A, B, C, D, E, F, H>(a: A, b: B, c: C, d: D, e: E, f: F, h: H): SchemaValidator<A | B | C | D | E | F | H, [Input<A> | Input<B> | Input<C> | Input<D> | Input<E> | Input<F> | Input<H>]>;
export declare function Or<A, B, C, D, E, F, H, J>(a: A, b: B, c: C, d: D, e: E, f: F, h: H, j: J): SchemaValidator<A | B | C | D | E | F | H | J, [Input<A> | Input<B> | Input<C> | Input<D> | Input<E> | Input<F> | Input<H> | Input<J>]>;
export declare function ArrayOf<T>(schema: T, error?: ErrorLike): FunctionType<ValidatorOutput<T>[], [Input<T>[]]>;
export declare function TypeOf<T extends 'string' | 'number' | 'object' | 'boolean' | 'symbol' | 'bigint' | 'undefined'>(typeOf: T, error?: ErrorLike): SyncFunctionValidator<TypeOfType<T>>;
export declare function Any<T>(input: T): T;
export declare function Override<T>(value: T): SyncFunctionValidator<T, [unknown?]>;
export declare function Test<T>(test: (input: T) => unknown, error?: ErrorLike): SyncFunctionValidator<T, [T]>;
export {};