@shopify/react-form-state
Version:
Manage react forms tersely and type-safe with no magic.
35 lines (34 loc) • 2.05 kB
TypeScript
interface Matcher<Input, Fields> {
(input: Input, fields: Fields): boolean;
}
interface StringMapper {
(input: string): any;
}
declare type ErrorContent = string | StringMapper;
export declare function lengthMoreThan(length: number): (input: {
length: number;
}) => boolean;
export declare function lengthLessThan(length: number): (input: {
length: number;
}) => boolean;
export declare function isNumericString(input: string): boolean;
export declare function isEmpty(input: any): boolean;
export declare function isEmptyString(input: string): boolean;
export declare function not<A extends Array<any>, R>(fn: (...a: A) => R): (...args: A) => boolean;
export declare function validateNested<Input extends Object, Fields>(validatorDictionary: any): (input: Input, fields: Fields) => any;
export declare function validateList<Input extends Object, Fields>(validatorDictionary: any): (input: Input[], fields: Fields) => any[] | undefined;
export declare function validate<Input>(matcher: Matcher<Input, any>, errorContent: ErrorContent): (input: Input) => ErrorContent | undefined | void;
export declare function validateRequired<Input>(matcher: Matcher<Input, any>, errorContent: ErrorContent): (input: Input) => ErrorContent | undefined | void;
declare const validators: {
lengthMoreThan(length: number, errorContent: ErrorContent): (input: {
length: number;
}) => string | void | StringMapper | undefined;
lengthLessThan(length: number, errorContent: ErrorContent): (input: {
length: number;
}) => string | void | StringMapper | undefined;
numericString(errorContent: ErrorContent): (input: string) => string | void | StringMapper | undefined;
nonNumericString(errorContent: ErrorContent): (input: string) => string | void | StringMapper | undefined;
requiredString(errorContent: ErrorContent): (input: string) => string | void | StringMapper | undefined;
required(errorContent: ErrorContent): (input: any) => string | void | StringMapper | undefined;
};
export default validators;