-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.js.flow
97 lines (84 loc) · 3.03 KB
/
rules.js.flow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* https://github.com/atmulyana/react-native-form-input-validator
*
* @format
* @flow
*/
import type {
ComparableType,
HttpReqOption,
StrLengthType,
ValidateFunction,
ValidateFunctionAsync,
} from './lib/types';
import Rule from './lib/rules/Rule';
declare export class ValidationRule<T> extends Rule<T> {
validate(): Rule<T>;
}
declare export class ValidationRuleAsync<T> extends Rule<T> {
validate(): Promise<Rule<T>>;
}
declare export class CustomRule extends ValidationRule<mixed> {
constructor(validateFunc: ValidateFunction<mixed>, errorMessage?: string): void;
}
declare export function rule(
validateFunc: ValidateFunction<mixed>,
errorMessage?: string
): Rule<mixed>;
declare export class CustomRuleAsync extends ValidationRuleAsync<mixed> {
constructor(validateFunc: ValidateFunctionAsync<mixed>, errorMessage?: string): void;
}
declare export function ruleAsync(
validateFunc: ValidateFunctionAsync<mixed>,
errorMessage?: string
): Rule<mixed>;
declare export class Email extends ValidationRule<string> {}
export const email: Rule<string> = new Email();
declare export class HttpReq extends ValidationRuleAsync<?ComparableType | boolean> {
constructor(uri: string, option?: HttpReqOption): void;
}
declare export function httpReq(
uri: string,
option?: HttpReqOption
): HttpReq;
declare export class Integer extends ValidationRule<mixed>{}
export const integer: Rule<mixed> = new Integer();
declare export class Max extends ValidationRule<ComparableType> {
constructor(max: ComparableType | () => ComparableType): void;
max: ComparableType | () => ComparableType;
}
declare export function max(
maxVal: ComparableType | (() => ComparableType)
): Rule<ComparableType>;
declare export class Min extends ValidationRule<ComparableType> {
constructor(min: ComparableType | () => ComparableType): void;
min: ComparableType | () => ComparableType;
}
declare export function min(
minVal: ComparableType | (() => ComparableType)
): Rule<ComparableType>;
declare export class Numeric extends ValidationRule<string>{}
export const numeric: Rule<string> = new Numeric();
declare export class Regex extends ValidationRule<string> {
constructor(pattern: RegExp | string, flags?: string): void;
}
declare export function regex(
pattern: RegExp | string,
flags?: string
): Rule<string>;
declare export class Required extends ValidationRule<mixed> {
constructor(_if?: mixed => boolean): void;
static If(_if: mixed => boolean): Required;
}
class RequiredIf extends Required {
if: (mixed => boolean) => Required = Required.If.bind(null);
}
export const required: RequiredIf = new RequiredIf();
export const alwaysValid: Required = Required.If(() => false);
declare export class StrLength extends ValidationRule<StrLengthType> {
constructor(min?: number, max?: number): void;
min: number | void;
max: number | void;
}
declare export function strlen(min: number, max?: number): Rule<StrLengthType>;
declare export function strlenmax(max: number): Rule<StrLengthType>;