index.d.ts
8.21 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/**
* Exposes an interface to extend the validator and add new methods to it.
*/
export function extend(name: string, method: ValidationMethod, message?: string): void;
/**
* Sanitizes a given set of data with given set of rules.
*/
export function sanitize<T>(data: T, rules: Rules): T;
/**
* Validate a set of async validations mapped as field and rule called rules.
*/
export function validate<T>(data: T, rules: Rules, messages?: Messages): Promise<T>;
/**
* Just like validate but waits for all the validations to occur and returns an array of errors.
*/
export function validateAll<T>(data: T, rules: Rules, messages?: Messages): Promise<T>;
export namespace is {
/**
* Tells whether input is above comparison input.
*/
function above(input: number, comparsionInput: number): boolean;
/**
* Tells whether input is affirmative or not.
*/
function affirmative(input: string): boolean;
/**
* Tells whether input is after given date.
*/
function after(input: string | Date, afterDate: string | Date): boolean;
/**
* Tells whether input is after certain offset from current date.
*/
function afterOffsetOf(input: string, number: number, key: string): boolean;
/**
* Makes sure given field contains letters only.
*/
function alpha(input: string): boolean;
/**
* Tells whether input is a valid alpha numeric string or not.
*/
function alphaNumeric(input: string | number): boolean;
/**
* Tells whether input is a valid array or not.
*/
function array(input: any[]): boolean;
/**
* Tells whether input is before a given date.
*/
function before(input: string | Date, beforeDate: string | Date): boolean;
/**
* Tells whether input is before certain offset from current date.
*/
function beforeOffsetOf(input: string, number: number, key: string): any;
/**
* Tells whether a value lies between 2 values or not.
*/
function between(input: number, min: number, max: number): boolean;
/**
* Tells whether input is a valid credit card number or not.
*/
function creditCard(input: string): boolean;
/**
* Tells whether input is a valid date or not .
*/
function date(input: string | Date, strict: boolean): boolean;
/**
* Tells whether input is a valid date for a given format or not.
*/
function dateFormat(input: string, formats: any[]): boolean;
/**
* Tells whether given input is a valid email address or not.
*/
function email(input: string): boolean;
/**
* Tells whether input is empty or not.
*/
function empty(input: any): boolean;
/**
* Tells whether input is a even number or not.
*/
function even(input: number): boolean;
/**
* Tells whether input exists or not.
*/
function existy(input: any): boolean;
/**
* Exposes an interface to extend the raw validator and add own methods to it.
*/
function extend(name: string, method: Function): void;
/**
* Tells whether input is falsy or not, opposite of truthy.
*/
function falsy(input: any): boolean;
/**
* Tells whether input date is in future or not.
*/
function future(input: string | Date): boolean;
/**
* Tells whether a value lies in an array or not.
*/
function inArray(input: string, comparsionArray: any[]): boolean;
/**
* Tells whether a given date is between 2 dates or not.
*/
function inDateRange(input: string | Date, minDate: string | Date, maxDate: string | Date): boolean;
/**
* Makes sure all values of one array are present in another array.
*/
function intersectAll(input: any[], intersectionArray: any[]): boolean;
/**
* Makes sure any one value of one array is present in another array.
*/
function intersectAny(input: any[], intersectionArray: any[]): boolean;
/**
* Tells whether ip address is a valid ipv4 or ipv6 ip address.
*/
function ip(input: string): boolean;
/**
* Tells whether ip address is a valid ipv4 ip address.
*/
function ipv4(input: string): boolean;
/**
* Tells whether ip address is a valid ipv6 ip address.
*/
function ipv6(input: string): boolean;
/**
* Tells whether input is a valid JSON string or not.
*/
function json(input: string): boolean;
/**
* Tells whether input is a negative number or not.
*/
function negative(input: number): boolean;
/**
* Tells type of input is a valid number or not.
*/
function number(input: any): boolean;
/**
* Tells whether input is a valid object or not.
*/
function object(input: any): boolean;
/**
* Tells whether input is a odd number or not.
*/
function odd(input: number): boolean;
/**
* Tells whether input date is in past or not.
*/
function past(input: string | Date): boolean;
/**
* Tells whether given input is a valid phone number or not.
*/
function phone(input: string | number): boolean;
/**
* Tells whether input is a positive number or not.
*/
function positive(input: number): boolean;
/**
* Executes a given regex on a given input.
*/
function regex(input: string, regex: string | RegExp): boolean;
/**
* Tells whether 2 values are identically same.
*/
function same(input: any, comparsionInput: any): boolean;
/**
* Matches 2 input are of same type or not.
*/
function sameType(input: any, comparsionInput: any): boolean;
/**
* Tells whether an array is sorted or not.
*/
function sorted(input: any[]): boolean;
/**
* Tells whether input is of type string or not.
*/
function string(input: any): boolean;
/**
* Tells whether input date is a valid date is today or not.
*/
function today(input: string | Date): boolean;
/**
* Tells whether input date is a valid date to tomorrow or not.
*/
function tomorrow(input: string | Date): boolean;
/**
* Tells whether input is truthy or not.
*/
function truthy(input: any): boolean;
/**
* Tells whether input is under comparison input.
*/
function under(input: number, comparsionInput: number): boolean;
/**
* Tells whether given input is a valid url or not.
*/
function url(input: string): boolean;
/**
* Tells whether input date is a valid date from yesterday or not.
*/
function yesterday(input: any): any;
}
export namespace sanitizor {
/**
* Removes blacklisted values from string.
*/
function blacklist(value: string, args: any[]): string;
function camelCase(value: string): string;
function capitalize(value: string): string;
function decapitalize(value: string): string;
/**
* Escapes an input if it's a string.
*/
function escape(value: string): string;
function escape(value: any): any;
/**
* Exposes an interface to extend filters.
*/
function extend(name: string, method: Function): void;
function humanize(value: string): string;
/**
* Normalizes an email by removing all unncessary characters from it.
*/
function normalizeEmail(value: string, args: any[]): string;
function plural(value: string): string;
function singular(value: string): string;
function slug(value: string): string;
function stripLinks(value: string): string;
function stripTags(value: string, args: any[]): string;
function title(value: string): string;
/**
* Coverts a value to boolean all values with positive inputs yields to true.
*/
function toBoolean(value: any): boolean;
function toDash(value: string): string;
/**
* Converts a date to a date object or return null when invalid date
*/
function toDate(value: any): Date | null;
/**
* Converts a value to float or returns NaN when unable to make it a flat.
*/
function toFloat(value: any): number;
/**
* Coverts a value to integer or returns NaN.
*/
function toInt(value: any, args: any[]): number;
function underscore(value: string): string;
}
export interface ValidationMethod {
(data: any, field: string, message: string, args: any[], get: Function): Promise<any>;
}
export interface MessageMethod {
(field: string, validation: string, args: any[]): string;
}
export interface Error {
field?: string;
validation?: string;
message?: string;
}
export interface Data {
[x: string]: any;
}
export interface Rules {
[x: string]: string;
}
export interface Messages {
[x: string]: string | MessageMethod;
}