-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.d.ts
311 lines (233 loc) · 11.2 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
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
// Type definitions for validator.js v7.0.0
// Project: https://github.com/chriso/validator.js
// Definitions by: tgfjt <https://github.com/tgfjt>, Ilya Mochalov <https://github.com/chrootsu>, Ayman Nedjmeddine <https://github.com/IOAyman>, Louy Alakkad <https://github.com/louy>
declare namespace validator {
interface ValidatorStatic {
// **************
// * Validators *
// **************
// check if the string contains the seed.
contains(str: string, elem: any): boolean;
// check if the string matches the comparison.
equals(str: string, comparison: any): boolean;
// check if the string is a date that's after the specified date (defaults to now).
isAfter(str: string, date?: string): boolean;
// check if the string contains only letters (a-zA-Z). Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG',
// 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE',
// 'cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU',
// 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR']) and defaults to en-US
isAlpha(str: string, local?: string): boolean;
// check if the string contains only letters and numbers. Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG',
// 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE',
// 'cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU',
// 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR']) and defaults to en-US
isAlphanumeric(str: string, local?: string): boolean;
// check if the string contains ASCII chars only.
isAscii(str: string): boolean;
// check if a string is base32 encoded.
isBase32(str: string): boolean;
// check if a string is base64 encoded.
isBase64(str: string): boolean;
// check if the string is a date that's before the specified date.
isBefore(str: string, date?: string): boolean;
// check if a string is a boolean.
isBoolean(str: string): boolean;
// check if the string's length (in bytes) falls in a range.
isByteLength(str: string, options: IsByteLengthOptions): boolean;
isByteLength(str: string, min: number, max?: number): boolean;
// check if the string is a credit card.
isCreditCard(str: string): boolean;
// check if the string is a valid currency amount.
isCurrency(str: string, options?: IsCurrencyOptions): boolean;
// check if the string is a data uri format (https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs)
isDataURI(str: string): boolean;
// check if the string is a magnet uri format
isMagnetURI(str: string): boolean;
// check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.
isDecimal(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 an email.
isEmail(str: string, options?: IsEmailOptions): boolean;
// check if the string is a fully qualified domain name (e.g. domain.com).
isFQDN(str: string, options?: IsFQDNOptions): boolean;
// check if the string is a float.
isFloat(str: string, options?: IsFloatOptions): 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 is a hexadecimal color.
isHexColor(str: string): boolean;
// check if the string is a hexadecimal number.
isHexadecimal(str: string): boolean;
// check if the string is a valid identity card code.
// locale is one of ['ES', 'zh-TW', 'he-IL'] OR 'any'. If 'any' is used, function will check if any of the locals match.
isIdentityCard(str: string, locale: string): boolean;
// check if the string is an IP (version 4 or 6).
isIP(str: string, version?: number): boolean;
// check if the string is an IP Range (version 4 only).
isIPRange(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 an ISIN (https://en.wikipedia.org/wiki/International_Securities_Identification_Number)
// (stock/security identifier).
isISIN(str: string): boolean;
// check if the string is a valid ISO 8601 (https://en.wikipedia.org/wiki/ISO_8601) date.
isISO8601(str: string): boolean;
// check if the string is a valid RFC 3339 date.
isRFC3339(str: string): boolean;
// check if the string is in a array of allowed values.
isIn(str: string, values: any[]): boolean;
// check if the string is an integer.
isInt(str: string, options?: IsIntOptions): boolean;
// check if the string is valid JSON (note: uses JSON.parse).
isJSON(str: string): boolean;
// check if the string's length falls in a range.
// Note: this function takes into account surrogate pairs.
isLength(str: string, options: IsLengthOptions): boolean;
isLength(str: string, min: number, max?: number): boolean;
// check if the string is lowercase.
isLowercase(str: string): boolean;
// check if the string is a MAC address.
isMACAddress(str: string): boolean;
// check if the string is a MD5 hash.
isMD5(str: string): boolean;
// check if the string is a mobile phone number, (locale is one of
// ['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK',
// 'en-IN', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'hu-HU',
// 'it-IT', 'ja-JP', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ru-RU', 'sr-RS', 'tr-TR',
// 'vi-VN', 'zh-CN', 'zh-TW']).
isMobilePhone(str: string, locale: string): boolean;
// check if the string is a valid hex-encoded representation of a MongoDB ObjectId
// (http://docs.mongodb.org/manual/reference/object-id/).
isMongoId(str: string): boolean;
// check if the string contains one or more multibyte chars.
isMultibyte(str: string): boolean;
// check if the string is null.
isEmpty(str: string): boolean;
// check if the string contains only numbers.
isNumeric(str: string): boolean;
// check if the string contains any surrogate pairs chars.
isSurrogatePair(str: string): boolean;
// check if the string is an URL.
isURL(str: string, options?: IsURLOptions): boolean;
// check if the string is a UUID. Must be one of ['3', '4', '5', 'all'], default is all.
isUUID(str: string, version?: string|number): boolean;
// check if the string is uppercase.
isUppercase(str: string): boolean;
// check if the string contains a mixture of full and half-width chars.
isVariableWidth(str: string): boolean;
// checks characters if they appear in the whitelist.
isWhitelisted(str: string, chars: string|string[]): boolean;
// check if string matches the pattern.
matches(str: string, pattern: RegExp|string, modifiers?: string): boolean;
// **************
// * Sanitizers *
// **************
// remove characters that appear in the blacklist. The characters are used in a RegExp and so you will need
// to escape some chars, e.g. blacklist(input, '\\[\\]').
blacklist(input: string, chars: string): string;
// replace <, >, &, ', " and / with HTML entities.
escape(input: string): string;
// replaces HTML encoded entities with <, >, &, ', " and /.
unescape(input: string): string;
// trim characters from the left-side of the input.
ltrim(input: any, chars?: string): string;
// canonicalize an email address.
normalizeEmail(email: string, options?: NormalizeEmailOptions): string;
// trim characters from the right-side of the input.
rtrim(input: any, chars?: string): string;
// remove characters with a numerical value < 32 and 127, mostly control characters. If keep_new_lines is true,
// newline characters are preserved (\n and \r, hex 0xA and 0xD). Unicode-safe in JavaScript.
stripLow(input: string, keep_new_lines?: boolean): string;
// convert the input to a boolean. Everything except for '0', 'false' and '' returns true. In strict mode only '1'
// and 'true' return true.
toBoolean(input: any, strict?: boolean): boolean;
// convert the input to a date, or null if the input is not a date.
toDate(input: any): Date; // 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
// trim characters (whitespace by default) from both sides of the input.
trim(input: any, chars?: string): string;
// remove characters that do not appear in the whitelist. The characters are used in a RegExp and so you will
// need to escape some chars, e.g. whitelist(input, '\\[\\]').
whitelist(input: string, chars: string): string;
// **************
// * Extensions *
// **************
// add your own validators.
// Note: that the first argument will be automatically coerced to a string.
extend<T extends Function>(name: string, fn: T): void;
}
// options for IsByteLength
interface IsByteLengthOptions {
min?: number;
max?: number;
}
// options for IsCurrency
interface IsCurrencyOptions {
symbol?: string;
require_symbol?: boolean;
allow_space_after_symbol?: boolean;
symbol_after_digits?: boolean;
allow_negatives?: boolean;
parens_for_negatives?: boolean;
negative_sign_before_digits?: boolean;
negative_sign_after_digits?: boolean;
allow_negative_sign_placeholder?: boolean;
thousands_separator?: string;
decimal_separator?: string;
allow_space_after_digits?: boolean;
}
// options for isEmail
interface IsEmailOptions {
allow_display_name?: boolean;
allow_utf8_local_part?: boolean;
require_tld?: boolean;
}
// options for isFQDN
interface IsFQDNOptions {
require_tld?: boolean;
allow_underscores?: boolean;
allow_trailing_dot?: boolean;
}
// options for IsFloat
interface IsFloatOptions {
min?: number;
max?: number;
}
// options for IsInt
interface IsIntOptions {
min?: number;
max?: number;
}
// options for IsLength
interface IsLengthOptions {
min?: number;
max?: number;
}
// options for isURL
interface IsURLOptions {
protocols?: string[];
require_tld?: boolean;
require_protocol?: boolean;
require_host: boolean;
require_valid_protocol?: boolean;
allow_underscores?: boolean;
host_whitelist?: (string|RegExp)[];
host_blacklist?: (string|RegExp)[];
allow_trailing_dot?: boolean;
allow_protocol_relative_urls?: boolean;
}
// options for normalizeEmail
interface NormalizeEmailOptions {
lowercase?: boolean;
remove_dots?: boolean;
remove_extension?: boolean;
}
}
declare const validator: validator.ValidatorStatic;
export = validator;