-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
164 lines (151 loc) · 4.56 KB
/
index.d.ts
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* Represents a list of errors in a string array.
*/
declare class IDetailsErrorObject {
/**
* List of errors.
*/
_: string[];
}
/**
* Represents available options for objects.
*/
declare interface IObjectOptions {
/**
* Flag as true to require all input values to be defined by the format in order to be valid. Default: true
*/
strict?: boolean;
/**
* Flag as true on a property to make that property not required (if the input has the property the format for that property is applied)
*/
optional?: boolean;
}
/**
* Represents available options for strings.
*/
declare interface IStringOptions {
/**
* Set a string to whitelist the input string.
*/
allowed?: string;
/**
* Set a string to blacklist the input string.
*/
banned?: string;
/**
* Flag as true to required the string be a valid email.
*/
email?: string;
/**
* Flag as true to required the string be lowercase.
*/
lowercase?: boolean;
/**
* Set the minimum required length of the string. Default: 1
*/
minLength?: number;
/**
* Set the maximum required length of the string.
*/
maxLength?: number;
/**
* Set the exact required length of the string.
*/
length?: number;
/**
* Set a regular expression to test the input string.
*/
regex?: RegExp;
/**
* Flag as true to required the string be uppercase.
*/
uppercase?: boolean;
/**
* Flag as false to ban whitespace.
*/
whitespace?: boolean;
/**
* Flag as false to ban whitespace at the beginning and end of the string
**/
trimmed?: boolean;
}
/**
* Represents available options for numbers.
*/
declare interface INumberOptions {
/**
* Flag as true to allow NaN. Default: false
*/
allowNaN?: boolean;
/**
* Flag as false to allow Infinity. Default: true
*/
finite?: boolean;
/**
* Set the minimum value of the input
*/
min?: number;
/**
* Set the maximum value of the input
*/
max?: number;
/**
* Flag as true to require even numbers.
*/
even?: number;
/**
* Flag as true to require odd numbers.
*/
odd?: number;
}
/**
* Represents available options for booleans.
*/
declare interface IBooleanOptions {
/**
* Checks if boolean is equal to this value.
*/
equalTo?: boolean;
}
declare interface IParameterizedOptionsBase {
_: ParameterTypes;
}
declare interface IParamaterizedStringOptions extends INumberOptions, IParameterizedOptionsBase {}
declare interface IParamaterizedNumberOptions extends INumberOptions, IParameterizedOptionsBase {}
declare interface IParamaterizedBooleanOptions extends IBooleanOptions, IParameterizedOptionsBase {}
declare interface IParameterizedObjectOptions extends IObjectOptions, IParameterizedOptionsBase {}
declare type ParameterTypes = IObjectOptions | INumberOptions | IStringOptions | IBooleanOptions;
declare type ParameterizedOptions = IParamaterizedBooleanOptions | IParamaterizedNumberOptions | IParameterizedObjectOptions | IParamaterizedStringOptions;
declare type VariableType = StringConstructor | BooleanConstructor | NumberConstructor | ObjectConstructor | undefined | null;
/**
* Contains core features of sandhands.
*/
declare interface Sandhands {
/**
* Returns a array/object representing where and what the errors are dependant upon the format.
* @param value Value to get details for.
* @param type Type to get details for.
* @param options Options to get details with.
*/
details: (value: any,
type: VariableType | ParameterizedOptions, options?: ParameterTypes) => string[] | IDetailsErrorObject;
/**
* Throws the first error found in the input.
* @param value Value to sanitize.
* @param type Type to check for.
* @param options Options to sanitize with.
*/
sanitize: (value: any,
type: VariableType | ParameterizedOptions, options?: ParameterTypes) => void;
/**
* Returns a boolean repesenting whether or not the input matched the format.
* @param value Value to valid.
* @param type Type to check for.
* @param options Options to valid with.
*/
valid: (value: any,
type: VariableType | ParameterizedOptions,
options?: ParameterTypes) => boolean;
}
declare var sandhands: Sandhands;
export = sandhands;