forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.d.ts
190 lines (134 loc) · 5.71 KB
/
validator.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
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
// Type definitions for validator.js v3.22.1
// Project: https://github.com/chriso/validator.js
// Definitions by: tgfjt <https://github.com/tgfjt>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// options for #isURL
interface IURLoptions {
protocols?: string[]
require_tld?: boolean
require_protocol?: boolean
allow_underscores?: boolean
}
// options for isFQDN
interface IFQDNoptions {
require_tld?: boolean
allow_underscores?: boolean
}
// options for normalizeEmail
interface IEmailoptions {
lowercase?: boolean
}
// callback type for #extend
interface IExtendCallback {
(argv: string): any
}
// return function for #extend
interface IExtendFunc {
(argv: string): boolean
}
interface IValidatorStatic {
// add your own validators
extend(name: string, fn: IExtendCallback): IExtendFunc;
// check if the string matches the comparison.
equals(str: string, comparison: any): boolean;
// check if the string contains the seed.
contains(str: string, elem: any): boolean;
// check if string matches the pattern.
matches(str: string, pattern: any, modifiers?: string): boolean;
// check if the string is an email.
isEmail(str: string): boolean;
// check if the string is an URL.
isURL(str: string, options?: IURLoptions): boolean;
// check if the string is a fully qualified domain name (e.g. domain.com).
isFQDN(str: string, options?: IFQDNoptions): boolean;
// check if the string is an IP (version 4 or 6).
isIP(str: string, version?: number): boolean;
// check if the string contains only letters (a-zA-Z).
isAlpha(str: string): boolean;
// check if the string contains only numbers.
isNumeric(str: string): boolean;
// check if the string contains only letters and numbers.
isAlphanumeric(str: string): boolean;
// check if a string is base64 encoded.
isBase64(str: string): boolean;
// check if the string is a hexadecimal number.
isHexadecimal(str: string): boolean;
// check if the string is a hexadecimal color.
isHexColor(str: string): boolean;
// check if the string is lowercase.
isLowercase(str: string): boolean;
// check if the string is uppercase.
isUppercase(str: string): boolean;
// check if the string is an integer.
isInt(str: string): boolean;
// check if the string is a float.
isFloat(str: string): boolean;
// check if the string is a number that's divisible by another.
isDivisibleBy(str: string, number: number): boolean;
// check if the string is null.
isNull(str: string): boolean;
// check if the string's length falls in a range. Note: this function takes into account surrogate pairs.
isLength(str: string, min: number, max?: number): boolean;
// check if the string's length (in bytes) falls in a range.
isByteLength(str: string, min: number, max?: number): boolean;
// check if the string is a UUID (version 3, 4 or 5).
isUUID(str: string, version?: number): boolean;
// check if the string is a date.
isDate(str: string): boolean;
// check if the string is a date that's after the specified date (defaults to now).
isAfter(str: string, date?: Date): boolean;
// check if the string is a date that's before the specified date.
isBefore(str: string, date?: Date): boolean;
// check if the string is in a array of allowed values.
isIn(str: string, values: any[]): boolean;
// check if the string is a credit card.
isCreditCard(str: string): boolean;
// check if the string is an ISBN (version 10 or 13).
isISBN(str: string, version?: number): boolean;
// check if the string is valid JSON (note: uses JSON.parse).
isJSON(str: string): boolean;
// check if the string contains one or more multibyte chars.
isMultibyte(str: string): boolean;
// check if the string contains ASCII chars only.
isAscii(str: string): boolean;
// check if the string contains any full-width chars.
isFullWidth(str: string): boolean;
// check if the string contains any half-width chars.
isHalfWidth(str: string): boolean;
// check if the string contains a mixture of full and half-width chars.
isVariableWidth(str: string): boolean;
// check if the string contains any surrogate pairs chars.
isSurrogatePair(str: string): boolean;
// check if the string is a valid hex-encoded representation of a MongoDB ObjectId.
isMongoId(str: string): boolean;
// convert the input to a string.
toString(input: any): string;
// convert the input to a date, or null if the input is not a date.
toDate(input: any): any; // Date or null
// convert the input to a float, or NaN if the input is not a float.
toFloat(input:any): number; // number or NaN
// convert the input to an integer, or NaN if the input is not an integer.
toInt(input:any, radix?: number): number; // number or NaN
// convert the input to a boolean.
toBoolean(input:any, strict?: boolean): boolean;
// trim characters (whitespace by default) from both sides of the input.
trim(input: any, chars?: string): string;
// trim characters from the left-side of the input.
ltrim(input: any, chars?: string): string;
// trim characters from the right-side of the input.
rtrim(input: any, chars?: string): string;
// replace <, >, &, ' and " with HTML entities.
escape(input: string): string;
// remove characters with a numerical value < 32 and 127
stripLow(input: string, keep_new_lines?: boolean): string;
// remove characters that do not appear in the whitelist.
whitelist(input: string, chars: string): string;
// remove characters that appear in the blacklist.
blacklist(input: string, chars: string): string;
// canonicalize an email address.
normalizeEmail(email: string, options?: IEmailoptions): string;
}
declare module "validator" {
var validator: IValidatorStatic;
export = validator;
}