1 | // Type definitions for validator.js 12.0
|
2 | // Project: https://github.com/validatorjs/validator.js
|
3 | // Definitions by: tgfjt <https://github.com/tgfjt>
|
4 | // Ilya Mochalov <https://github.com/chrootsu>
|
5 | // Ayman Nedjmeddine <https://github.com/IOAyman>
|
6 | // Louay Alakkad <https://github.com/louy>
|
7 | // Kacper Polak <https://github.com/kacepe>
|
8 | // Bonggyun Lee <https://github.com/deptno>
|
9 | // Naoto Yokoyama <https://github.com/builtinnya>
|
10 | // Philipp Katz <https://github.com/qqilihq>
|
11 | // Jace Warren <https://github.com/keatz55>
|
12 | // Munif Tanjim <https://github.com/MunifTanjim>
|
13 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
14 | // TypeScript Version: 2.1
|
15 |
|
16 | declare namespace validator {
|
17 | const version: string;
|
18 |
|
19 | /******************
|
20 | *** Validators ***
|
21 | ******************/
|
22 |
|
23 | /**
|
24 | * Check if the string contains the seed.
|
25 | *
|
26 | * @param seed - Seed
|
27 | */
|
28 | function contains(str: string, seed: any): boolean;
|
29 |
|
30 | /**
|
31 | * Check if the string matches the comparison.
|
32 | *
|
33 | * @param comparison - String to compare
|
34 | */
|
35 | function equals(str: string, comparison: string): boolean;
|
36 |
|
37 | /**
|
38 | * Check if the string is a date that's after the specified date.
|
39 | *
|
40 | * @param [date] - Date string (defaults to now)
|
41 | */
|
42 | function isAfter(str: string, date?: string): boolean;
|
43 |
|
44 | type AlphaLocale =
|
45 | | 'en-US'
|
46 | | 'bg-BG'
|
47 | | 'cs-CZ'
|
48 | | 'da-DK'
|
49 | | 'de-DE'
|
50 | | 'el-GR'
|
51 | | 'es-ES'
|
52 | | 'fr-FR'
|
53 | | 'it-IT'
|
54 | | 'nb-NO'
|
55 | | 'nl-NL'
|
56 | | 'nn-NO'
|
57 | | 'hu-HU'
|
58 | | 'pl-PL'
|
59 | | 'pt-PT'
|
60 | | 'ru-RU'
|
61 | | 'sl-SI'
|
62 | | 'sk-SK'
|
63 | | 'sr-RS@latin'
|
64 | | 'sr-RS'
|
65 | | 'sv-SE'
|
66 | | 'tr-TR'
|
67 | | 'uk-UA'
|
68 | | 'ku-IQ'
|
69 | | 'ar'
|
70 | | 'he'
|
71 | | 'fa-IR'
|
72 | | 'en-AU'
|
73 | | 'en-GB'
|
74 | | 'en-HK'
|
75 | | 'en-IN'
|
76 | | 'en-NZ'
|
77 | | 'en-ZA'
|
78 | | 'en-ZM'
|
79 | | 'ar-AE'
|
80 | | 'ar-BH'
|
81 | | 'ar-DZ'
|
82 | | 'ar-EG'
|
83 | | 'ar-IQ'
|
84 | | 'ar-JO'
|
85 | | 'ar-KW'
|
86 | | 'ar-LB'
|
87 | | 'ar-LY'
|
88 | | 'ar-MA'
|
89 | | 'ar-QM'
|
90 | | 'ar-QA'
|
91 | | 'ar-SA'
|
92 | | 'ar-SD'
|
93 | | 'ar-SY'
|
94 | | 'ar-TN'
|
95 | | 'ar-YE'
|
96 | | 'pt-BR'
|
97 | | 'pl-Pl';
|
98 |
|
99 | const isAlphaLocales: AlphaLocale[];
|
100 |
|
101 | /**
|
102 | * Check if the string contains only letters (a-zA-Z).
|
103 | *
|
104 | * @param [locale] - AlphaLocale
|
105 | */
|
106 | function isAlpha(str: string, locale?: AlphaLocale): boolean;
|
107 |
|
108 | type AlphanumericLocale =
|
109 | | 'en-US'
|
110 | | 'bg-BG'
|
111 | | 'cs-CZ'
|
112 | | 'da-DK'
|
113 | | 'de-DE'
|
114 | | 'el-GR'
|
115 | | 'es-ES'
|
116 | | 'fr-FR'
|
117 | | 'it-IT'
|
118 | | 'hu-HU'
|
119 | | 'nb-NO'
|
120 | | 'nl-NL'
|
121 | | 'nn-NO'
|
122 | | 'pl-PL'
|
123 | | 'pt-PT'
|
124 | | 'ru-RU'
|
125 | | 'sl-SI'
|
126 | | 'sk-SK'
|
127 | | 'sr-RS@latin'
|
128 | | 'sr-RS'
|
129 | | 'sv-SE'
|
130 | | 'tr-TR'
|
131 | | 'uk-UA'
|
132 | | 'ku-IQ'
|
133 | | 'ar'
|
134 | | 'he'
|
135 | | 'fa-IR'
|
136 | | 'en-AU'
|
137 | | 'en-GB'
|
138 | | 'en-HK'
|
139 | | 'en-IN'
|
140 | | 'en-NZ'
|
141 | | 'en-ZA'
|
142 | | 'en-ZM'
|
143 | | 'ar-AE'
|
144 | | 'ar-BH'
|
145 | | 'ar-DZ'
|
146 | | 'ar-EG'
|
147 | | 'ar-IQ'
|
148 | | 'ar-JO'
|
149 | | 'ar-KW'
|
150 | | 'ar-LB'
|
151 | | 'ar-LY'
|
152 | | 'ar-MA'
|
153 | | 'ar-QM'
|
154 | | 'ar-QA'
|
155 | | 'ar-SA'
|
156 | | 'ar-SD'
|
157 | | 'ar-SY'
|
158 | | 'ar-TN'
|
159 | | 'ar-YE'
|
160 | | 'pt-BR'
|
161 | | 'pl-Pl';
|
162 |
|
163 | const isAlphanumericLocales: AlphanumericLocale[];
|
164 |
|
165 | /**
|
166 | * Check if the string contains only letters and numbers.
|
167 | *
|
168 | * @param [locale] - AlphanumericLocale
|
169 | */
|
170 | function isAlphanumeric(str: string, locale?: AlphanumericLocale): boolean;
|
171 |
|
172 | /**
|
173 | * Check if the string contains ASCII chars only.
|
174 | */
|
175 | function isAscii(str: string): boolean;
|
176 |
|
177 | /**
|
178 | * Check if a string is base32 encoded.
|
179 | */
|
180 | function isBase32(str: string): boolean;
|
181 |
|
182 | /**
|
183 | * Check if a string is base64 encoded.
|
184 | */
|
185 | function isBase64(str: string): boolean;
|
186 |
|
187 | /**
|
188 | * Check if the string is a date that's before the specified date.
|
189 | *
|
190 | * @param [date] - Date string (defaults to now)
|
191 | */
|
192 | function isBefore(str: string, date?: string): boolean;
|
193 |
|
194 | /**
|
195 | * Check if a string is a BIC (Bank Identification Code) or SWIFT code.
|
196 | */
|
197 | function isBIC(str: string): boolean;
|
198 |
|
199 | /**
|
200 | * check if a string is a boolean.
|
201 | */
|
202 | function isBoolean(str: string): boolean;
|
203 |
|
204 | interface IsByteLengthOptions {
|
205 | /**
|
206 | * @default 0
|
207 | */
|
208 | min?: number;
|
209 | /**
|
210 | * @default undefined
|
211 | */
|
212 | max?: number;
|
213 | }
|
214 |
|
215 | /**
|
216 | * Check if the string's length (in UTF-8 bytes) falls in a range.
|
217 | *
|
218 | * @param [options] - Options
|
219 | */
|
220 | function isByteLength(str: string, options?: IsByteLengthOptions): boolean;
|
221 |
|
222 | /**
|
223 | * Check if the string is a credit card.
|
224 | */
|
225 | function isCreditCard(str: string): boolean;
|
226 |
|
227 | interface IsCurrencyOptions {
|
228 | /**
|
229 | * @default '$'
|
230 | */
|
231 | symbol?: string;
|
232 | /**
|
233 | * @default false
|
234 | */
|
235 | require_symbol?: boolean;
|
236 | /**
|
237 | * @default false
|
238 | */
|
239 | allow_space_after_symbol?: boolean;
|
240 | /**
|
241 | * @default false
|
242 | */
|
243 | symbol_after_digits?: boolean;
|
244 | /**
|
245 | * @default true
|
246 | */
|
247 | allow_negatives?: boolean;
|
248 | /**
|
249 | * @default false
|
250 | */
|
251 | parens_for_negatives?: boolean;
|
252 | /**
|
253 | * @default false
|
254 | */
|
255 | negative_sign_before_digits?: boolean;
|
256 | /**
|
257 | * @default false
|
258 | */
|
259 | negative_sign_after_digits?: boolean;
|
260 | /**
|
261 | * @default false
|
262 | */
|
263 | allow_negative_sign_placeholder?: boolean;
|
264 | /**
|
265 | * @default ','
|
266 | */
|
267 | thousands_separator?: string;
|
268 | /**
|
269 | * @default '.'
|
270 | */
|
271 | decimal_separator?: string;
|
272 | /**
|
273 | * @default true
|
274 | */
|
275 | allow_decimal?: boolean;
|
276 | /**
|
277 | * @default false
|
278 | */
|
279 | require_decimal?: boolean;
|
280 | /**
|
281 | * The array `digits_after_decimal` is filled with the exact number of digits allowed not a range, for example a range `1` to `3` will be given as `[1, 2, 3]`.
|
282 | *
|
283 | * @default [2]
|
284 | */
|
285 | digits_after_decimal?: number[];
|
286 | /**
|
287 | * @default false
|
288 | */
|
289 | allow_space_after_digits?: boolean;
|
290 | }
|
291 |
|
292 | /**
|
293 | * Check if the string is a valid currency amount.
|
294 | *
|
295 | * @param [options] - Options
|
296 | */
|
297 | function isCurrency(str: string, options?: IsCurrencyOptions): boolean;
|
298 |
|
299 | /**
|
300 | * Check if the string is a [data uri format](https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs).
|
301 | */
|
302 | function isDataURI(str: string): boolean;
|
303 |
|
304 | type DecimalLocale = FloatLocale;
|
305 |
|
306 | interface IsDecimalOptions {
|
307 | /**
|
308 | * @default false
|
309 | */
|
310 | force_decimal?: boolean;
|
311 | /**
|
312 | * `decimal_digits` is given as a range like `'1,3'`,
|
313 | * a specific value like `'3'` or min like `'1,'`
|
314 | *
|
315 | * @default '1,'
|
316 | */
|
317 | decimal_digits?: string;
|
318 | /**
|
319 | * DecimalLocale
|
320 | *
|
321 | * @default 'en-US'
|
322 | */
|
323 | locale?: DecimalLocale;
|
324 | }
|
325 |
|
326 | /**
|
327 | * Check if the string represents a decimal number,
|
328 | * such as `0.1`, `.3`, `1.1`, `1.00003`, `4.0` etc.
|
329 | *
|
330 | * @param [options] - Options
|
331 | */
|
332 | function isDecimal(str: string, options?: IsDecimalOptions): boolean;
|
333 |
|
334 | /**
|
335 | * Check if the string is a number that's divisible by another.
|
336 | *
|
337 | * @param number - Divider number
|
338 | */
|
339 | function isDivisibleBy(str: string, number: number): boolean;
|
340 |
|
341 | interface IsEmailOptions {
|
342 | /**
|
343 | * If `allow_display_name` is set to `true`, the validator will also match `Display Name <email-address>`.
|
344 | *
|
345 | * @default false
|
346 | */
|
347 | allow_display_name?: boolean;
|
348 | /**
|
349 | * If `require_display_name` is set to `true`, the validator will reject strings without the format `Display Name <email-address>`.
|
350 | *
|
351 | * @default false
|
352 | */
|
353 | require_display_name?: boolean;
|
354 | /**
|
355 | * If `allow_utf8_local_part` is set to `false`, the validator will not allow any non-English UTF8 character in email address' local part.
|
356 | *
|
357 | * @default true
|
358 | */
|
359 | allow_utf8_local_part?: boolean;
|
360 | /**
|
361 | * If `require_tld` is set to `false`, e-mail addresses without having TLD in their domain will also be matched.
|
362 | *
|
363 | * @default true
|
364 | */
|
365 | require_tld?: boolean;
|
366 | /**
|
367 | * If `ignore_max_length` is set to `true`, the validator will not check for the standard max length of an email.
|
368 | *
|
369 | * @default false
|
370 | */
|
371 | ignore_max_length?: boolean;
|
372 | /**
|
373 | * If `allow_ip_domain` is set to `true`, the validator will allow IP addresses in the host part.
|
374 | *
|
375 | * @default false
|
376 | */
|
377 | allow_ip_domain?: boolean;
|
378 | /**
|
379 | * If `domain_specific_validation` is `true`, some additional validation will be enabled,
|
380 | * e.g. disallowing certain syntactically valid email addresses that are rejected by GMail.
|
381 | *
|
382 | * @default false
|
383 | */
|
384 | domain_specific_validation?: boolean;
|
385 | }
|
386 |
|
387 | /**
|
388 | * Check if the string is an email.
|
389 | *
|
390 | * @param [options] - Options
|
391 | */
|
392 | function isEmail(str: string, options?: IsEmailOptions): boolean;
|
393 |
|
394 | interface IsEmptyOptions {
|
395 | /**
|
396 | * @default false
|
397 | */
|
398 | ignore_whitespace?: boolean;
|
399 | }
|
400 |
|
401 | /**
|
402 | * Check if the string has a length of zero.
|
403 | *
|
404 | * @param [options] - Options
|
405 | */
|
406 | function isEmpty(str: string, options?: IsEmptyOptions): boolean;
|
407 |
|
408 | type FloatLocale =
|
409 | | 'en-US'
|
410 | | 'ar'
|
411 | | 'en-AU'
|
412 | | 'en-GB'
|
413 | | 'en-HK'
|
414 | | 'en-IN'
|
415 | | 'en-NZ'
|
416 | | 'en-ZA'
|
417 | | 'en-ZM'
|
418 | | 'ar-AE'
|
419 | | 'ar-BH'
|
420 | | 'ar-DZ'
|
421 | | 'ar-EG'
|
422 | | 'ar-IQ'
|
423 | | 'ar-JO'
|
424 | | 'ar-KW'
|
425 | | 'ar-LB'
|
426 | | 'ar-LY'
|
427 | | 'ar-MA'
|
428 | | 'ar-QM'
|
429 | | 'ar-QA'
|
430 | | 'ar-SA'
|
431 | | 'ar-SD'
|
432 | | 'ar-SY'
|
433 | | 'ar-TN'
|
434 | | 'ar-YE'
|
435 | | 'bg-BG'
|
436 | | 'cs-CZ'
|
437 | | 'da-DK'
|
438 | | 'de-DE'
|
439 | | 'el-GR'
|
440 | | 'es-ES'
|
441 | | 'fr-FR'
|
442 | | 'it-IT'
|
443 | | 'ku-IQ'
|
444 | | 'hu-HU'
|
445 | | 'nb-NO'
|
446 | | 'nn-NO'
|
447 | | 'nl-NL'
|
448 | | 'pl-PL'
|
449 | | 'pt-PT'
|
450 | | 'ru-RU'
|
451 | | 'sl-SI'
|
452 | | 'sr-RS@latin'
|
453 | | 'sr-RS'
|
454 | | 'sv-SE'
|
455 | | 'tr-TR'
|
456 | | 'uk-UA'
|
457 | | 'pt-BR'
|
458 | | 'pl-Pl';
|
459 |
|
460 | const isFloatLocales: FloatLocale[];
|
461 |
|
462 | interface IsFloatOptions {
|
463 | /**
|
464 | * less or equal
|
465 | */
|
466 | min?: number;
|
467 | /**
|
468 | * greater or equal
|
469 | */
|
470 | max?: number;
|
471 | /**
|
472 | * greater than
|
473 | */
|
474 | gt?: number;
|
475 | /**
|
476 | * less than
|
477 | */
|
478 | lt?: number;
|
479 | /**
|
480 | * FloatLocale
|
481 | */
|
482 | locale?: FloatLocale;
|
483 | }
|
484 |
|
485 | /**
|
486 | * Check if the string is a float.
|
487 | *
|
488 | * @param [options] - Options
|
489 | */
|
490 | function isFloat(str: string, options?: IsFloatOptions): boolean;
|
491 |
|
492 | interface IsFQDNOptions {
|
493 | /**
|
494 | * @default true
|
495 | */
|
496 | require_tld?: boolean;
|
497 | /**
|
498 | * @default false
|
499 | */
|
500 | allow_underscores?: boolean;
|
501 | /**
|
502 | * @default false
|
503 | */
|
504 | allow_trailing_dot?: boolean;
|
505 | }
|
506 |
|
507 | /**
|
508 | * Check if the string is a fully qualified domain name (e.g. `domain.com`).
|
509 | *
|
510 | * @param [options] - Options
|
511 | */
|
512 | function isFQDN(str: string, options?: IsFQDNOptions): boolean;
|
513 |
|
514 | /**
|
515 | * Check if the string contains any full-width chars.
|
516 | */
|
517 | function isFullWidth(str: string): boolean;
|
518 |
|
519 | /**
|
520 | * Check if the string contains any half-width chars.
|
521 | */
|
522 | function isHalfWidth(str: string): boolean;
|
523 |
|
524 | type HashAlgorithm =
|
525 | | 'md4'
|
526 | | 'md5'
|
527 | | 'sha1'
|
528 | | 'sha256'
|
529 | | 'sha384'
|
530 | | 'sha512'
|
531 | | 'ripemd128'
|
532 | | 'ripemd160'
|
533 | | 'tiger128'
|
534 | | 'tiger160'
|
535 | | 'tiger192'
|
536 | | 'crc32'
|
537 | | 'crc32b';
|
538 |
|
539 | /**
|
540 | * Check if the string is a hash of type algorithm.
|
541 | *
|
542 | * @param algorithm - HashAlgorithm
|
543 | */
|
544 | function isHash(str: string, algorithm: HashAlgorithm): boolean;
|
545 |
|
546 | /**
|
547 | * Check if the string is a hexadecimal number.
|
548 | */
|
549 | function isHexadecimal(str: string): boolean;
|
550 |
|
551 | /**
|
552 | * Check if the string is a hexadecimal color.
|
553 | */
|
554 | function isHexColor(str: string): boolean;
|
555 |
|
556 | type IdentityCardLocale = 'ES' | 'he-IL' | 'zh-TW';
|
557 |
|
558 | /**
|
559 | * Check if the string is a valid identity card code.
|
560 | *
|
561 | * @param [locale="any"] - IdentityCardLocale
|
562 | */
|
563 | function isIdentityCard(str: string, locale?: 'any' | IdentityCardLocale): boolean;
|
564 |
|
565 | /**
|
566 | * Check if the string is in a array of allowed values.
|
567 | *
|
568 | * @param values - Allowed values.
|
569 | */
|
570 | function isIn(str: string, values: any[]): boolean;
|
571 |
|
572 | interface IsIntOptions {
|
573 | /**
|
574 | * to check the integer min boundary
|
575 | */
|
576 | min?: number;
|
577 | /**
|
578 | * to check the integer max boundary
|
579 | */
|
580 | max?: number;
|
581 | /**
|
582 | * if `false`, will disallow integer values with leading zeroes
|
583 | * @default true
|
584 | */
|
585 | allow_leading_zeroes?: boolean;
|
586 | /**
|
587 | * enforce integers being greater than the value provided
|
588 | */
|
589 | lt?: number;
|
590 | /**
|
591 | * enforce integers being less than the value provided
|
592 | */
|
593 | gt?: number;
|
594 | }
|
595 |
|
596 | /**
|
597 | * Check if the string is an integer.
|
598 | *
|
599 | * @param [options] - Options
|
600 | */
|
601 | function isInt(str: string, options?: IsIntOptions): boolean;
|
602 |
|
603 | /**
|
604 | * Check if the string is an IP (version 4 or 6).
|
605 | *
|
606 | * @param [version] - IP Version
|
607 | */
|
608 | function isIP(str: string, version?: '4' | '6'): boolean;
|
609 |
|
610 | /**
|
611 | * Check if the string is an IP Range (version 4 only).
|
612 | */
|
613 | function isIPRange(str: string): boolean;
|
614 |
|
615 | /**
|
616 | * Check if the string is an ISBN (version 10 or 13).
|
617 | *
|
618 | * @param [version] - ISBN Version
|
619 | */
|
620 | function isISBN(str: string, version?: '10' | '13'): boolean;
|
621 |
|
622 | /**
|
623 | * Check if the string is an [ISIN](https://en.wikipedia.org/wiki/International_Securities_Identification_Number) (stock/security identifier).
|
624 | */
|
625 | function isISIN(str: string): boolean;
|
626 |
|
627 | /**
|
628 | * Check if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code.
|
629 | */
|
630 | function isISO31661Alpha2(str: string): boolean;
|
631 |
|
632 | /**
|
633 | * Check if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code.
|
634 | */
|
635 | function isISO31661Alpha3(str: string): boolean;
|
636 |
|
637 | interface IsISO8601Options {
|
638 | /**
|
639 | * If `strict` is `true`, performs additional checks for valid dates,
|
640 | * e.g. invalidates dates like `2009-02-29`.
|
641 | *
|
642 | * @default false
|
643 | */
|
644 | strict?: boolean;
|
645 | }
|
646 |
|
647 | /**
|
648 | * Check if the string is a valid [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date.
|
649 | *
|
650 | * @param [options] - Options
|
651 | */
|
652 | function isISO8601(str: string, options?: IsISO8601Options): boolean;
|
653 |
|
654 | interface IsISSNOptions {
|
655 | /**
|
656 | * If `case_sensitive` is `true`, ISSNs with a lowercase `x` as the check digit are rejected.
|
657 | *
|
658 | * @default false
|
659 | */
|
660 | case_sensitive?: boolean;
|
661 | /**
|
662 | * @default false
|
663 | */
|
664 | require_hyphen?: boolean;
|
665 | }
|
666 |
|
667 | /**
|
668 | * Check if the string is an [ISSN](https://en.wikipedia.org/wiki/International_Standard_Serial_Number).
|
669 | *
|
670 | * @param [options] - Options
|
671 | */
|
672 | function isISSN(str: string, options?: IsISSNOptions): boolean;
|
673 |
|
674 | /**
|
675 | * Check if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code).
|
676 | */
|
677 | function isISRC(str: string): boolean;
|
678 |
|
679 | /**
|
680 | * Check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date.
|
681 | */
|
682 | function isRFC3339(str: string): boolean;
|
683 |
|
684 | /**
|
685 | * Check if the string is valid JSON (note: uses `JSON.parse`).
|
686 | */
|
687 | function isJSON(str: string): boolean;
|
688 |
|
689 | /**
|
690 | * Check if the string is valid JWT token.
|
691 | */
|
692 | function isJWT(str: string): boolean;
|
693 |
|
694 | /**
|
695 | * Check if the string is a valid latitude-longitude coordinate in the format:
|
696 | *
|
697 | * `lat,long` or `lat, long`.
|
698 | */
|
699 | function isLatLong(str: string): boolean;
|
700 |
|
701 | interface IsLengthOptions {
|
702 | /**
|
703 | * @default 0
|
704 | */
|
705 | min?: number;
|
706 | /**
|
707 | * @default undefined
|
708 | */
|
709 | max?: number;
|
710 | }
|
711 |
|
712 | /**
|
713 | * Check if the string's length falls in a range.
|
714 | *
|
715 | * Note: this function takes into account surrogate pairs.
|
716 | *
|
717 | * @param [options] - Options
|
718 | */
|
719 | function isLength(str: string, options?: IsLengthOptions): boolean;
|
720 |
|
721 | /**
|
722 | * Check if the string is lowercase.
|
723 | */
|
724 | function isLowercase(str: string): boolean;
|
725 |
|
726 | interface IsMACAddressOptions {
|
727 | /**
|
728 | * If `no_colons` is `true`, the validator will allow MAC addresses without the colons.
|
729 | * Also, it allows the use of hyphens or spaces.
|
730 | *
|
731 | * e.g. `01 02 03 04 05 ab` or `01-02-03-04-05-ab`.
|
732 | *
|
733 | * @default false
|
734 | */
|
735 | no_colons?: boolean;
|
736 | }
|
737 |
|
738 | /**
|
739 | * Check if the string is a MAC address.
|
740 | *
|
741 | * @param [options] - Options
|
742 | */
|
743 | function isMACAddress(str: string, options?: IsMACAddressOptions): boolean;
|
744 |
|
745 | /**
|
746 | * Check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme).
|
747 | */
|
748 | function isMagnetURI(str: string): boolean;
|
749 |
|
750 | /**
|
751 | * Check if the string is a MD5 hash.
|
752 | */
|
753 | function isMD5(str: string): boolean;
|
754 |
|
755 | /**
|
756 | * Check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format.
|
757 | */
|
758 | function isMimeType(str: string): boolean;
|
759 |
|
760 | type MobilePhoneLocale =
|
761 | | 'ar-AE'
|
762 | | 'ar-BH'
|
763 | | 'ar-DZ'
|
764 | | 'ar-EG'
|
765 | | 'ar-IQ'
|
766 | | 'ar-JO'
|
767 | | 'ar-KW'
|
768 | | 'ar-SA'
|
769 | | 'ar-SY'
|
770 | | 'ar-TN'
|
771 | | 'be-BY'
|
772 | | 'bg-BG'
|
773 | | 'bn-BD'
|
774 | | 'cs-CZ'
|
775 | | 'da-DK'
|
776 | | 'de-DE'
|
777 | | 'de-AT'
|
778 | | 'el-GR'
|
779 | | 'en-AU'
|
780 | | 'en-GB'
|
781 | | 'en-GG'
|
782 | | 'en-GH'
|
783 | | 'en-HK'
|
784 | | 'en-IE'
|
785 | | 'en-IN'
|
786 | | 'en-KE'
|
787 | | 'en-MT'
|
788 | | 'en-MU'
|
789 | | 'en-NG'
|
790 | | 'en-NZ'
|
791 | | 'en-PK'
|
792 | | 'en-RW'
|
793 | | 'en-SG'
|
794 | | 'en-TZ'
|
795 | | 'en-UG'
|
796 | | 'en-US'
|
797 | | 'en-ZA'
|
798 | | 'en-ZM'
|
799 | | 'es-CL'
|
800 | | 'es-ES'
|
801 | | 'es-MX'
|
802 | | 'es-PA'
|
803 | | 'es-PY'
|
804 | | 'es-UY'
|
805 | | 'et-EE'
|
806 | | 'fa-IR'
|
807 | | 'fi-FI'
|
808 | | 'fj-FJ'
|
809 | | 'fo-FO'
|
810 | | 'fr-FR'
|
811 | | 'fr-GF'
|
812 | | 'fr-GP'
|
813 | | 'fr-MQ'
|
814 | | 'fr-RE'
|
815 | | 'he-IL'
|
816 | | 'hu-HU'
|
817 | | 'id-ID'
|
818 | | 'it-IT'
|
819 | | 'ja-JP'
|
820 | | 'kk-KZ'
|
821 | | 'kl-GL'
|
822 | | 'ko-KR'
|
823 | | 'lt-LT'
|
824 | | 'ms-MY'
|
825 | | 'nb-NO'
|
826 | | 'nl-BE'
|
827 | | 'nl-NL'
|
828 | | 'nn-NO'
|
829 | | 'pl-PL'
|
830 | | 'pt-BR'
|
831 | | 'pt-PT'
|
832 | | 'ro-RO'
|
833 | | 'ru-RU'
|
834 | | 'sl-SI'
|
835 | | 'sk-SK'
|
836 | | 'sr-RS'
|
837 | | 'sv-SE'
|
838 | | 'th-TH'
|
839 | | 'tr-TR'
|
840 | | 'uk-UA'
|
841 | | 'vi-VN'
|
842 | | 'zh-CN'
|
843 | | 'zh-TW'
|
844 | | 'en-CA'
|
845 | | 'fr-BE'
|
846 | | 'zh-HK';
|
847 |
|
848 | const isMobilePhoneLocales: MobilePhoneLocale[];
|
849 |
|
850 | interface IsMobilePhoneOptions {
|
851 | /**
|
852 | * If this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`.
|
853 | *
|
854 | * @default false
|
855 | */
|
856 | strictMode?: boolean;
|
857 | }
|
858 |
|
859 | /**
|
860 | * Check if the string is a mobile phone number.
|
861 | *
|
862 | * @param [locale] - MobilePhoneLocale(s)
|
863 | * @param [options] - Options
|
864 | */
|
865 | function isMobilePhone(
|
866 | str: string,
|
867 | locale?: 'any' | MobilePhoneLocale | MobilePhoneLocale[],
|
868 | options?: IsMobilePhoneOptions,
|
869 | ): boolean;
|
870 |
|
871 | /**
|
872 | * Check if the string is a valid hex-encoded representation of a [MongoDB ObjectId](http://docs.mongodb.org/manual/reference/object-id/).
|
873 | */
|
874 | function isMongoId(str: string): boolean;
|
875 |
|
876 | /**
|
877 | * Check if the string contains one or more multibyte chars.
|
878 | */
|
879 | function isMultibyte(str: string): boolean;
|
880 |
|
881 | interface IsNumericOptions {
|
882 | /**
|
883 | * If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).
|
884 | *
|
885 | * @default false
|
886 | */
|
887 | no_symbols?: boolean;
|
888 | }
|
889 |
|
890 | /**
|
891 | * Check if the string contains only numbers.
|
892 | *
|
893 | * @param [options] - Options
|
894 | */
|
895 | function isNumeric(str: string, options?: IsNumericOptions): boolean;
|
896 |
|
897 | /**
|
898 | * Check if the string is a valid octal number.
|
899 | */
|
900 | function isOctal(str: string): boolean;
|
901 |
|
902 | /**
|
903 | * Check if the string is a valid port number.
|
904 | */
|
905 | function isPort(str: string): boolean;
|
906 |
|
907 | type PostalCodeLocale =
|
908 | | 'AD'
|
909 | | 'AT'
|
910 | | 'AU'
|
911 | | 'BE'
|
912 | | 'BG'
|
913 | | 'BR'
|
914 | | 'CA'
|
915 | | 'CH'
|
916 | | 'CZ'
|
917 | | 'DE'
|
918 | | 'DK'
|
919 | | 'DZ'
|
920 | | 'EE'
|
921 | | 'ES'
|
922 | | 'FI'
|
923 | | 'FR'
|
924 | | 'GB'
|
925 | | 'GR'
|
926 | | 'HR'
|
927 | | 'HU'
|
928 | | 'ID'
|
929 | | 'IE'
|
930 | | 'IL'
|
931 | | 'IN'
|
932 | | 'IS'
|
933 | | 'IT'
|
934 | | 'JP'
|
935 | | 'KE'
|
936 | | 'LI'
|
937 | | 'LT'
|
938 | | 'LU'
|
939 | | 'LV'
|
940 | | 'MX'
|
941 | | 'MT'
|
942 | | 'NL'
|
943 | | 'NO'
|
944 | | 'NZ'
|
945 | | 'PL'
|
946 | | 'PR'
|
947 | | 'PT'
|
948 | | 'RO'
|
949 | | 'RU'
|
950 | | 'SA'
|
951 | | 'SE'
|
952 | | 'SI'
|
953 | | 'SK'
|
954 | | 'TN'
|
955 | | 'TW'
|
956 | | 'UA'
|
957 | | 'US'
|
958 | | 'ZA'
|
959 | | 'ZM';
|
960 |
|
961 | const isPostalCodeLocales: PostalCodeLocale[];
|
962 |
|
963 | /**
|
964 | * Check if the string is a postal code
|
965 | *
|
966 | * @param locale - PostalCodeLocale
|
967 | */
|
968 | function isPostalCode(str: string, locale: 'any' | PostalCodeLocale): boolean;
|
969 |
|
970 | /**
|
971 | * Check if the string contains any surrogate pairs chars.
|
972 | */
|
973 | function isSurrogatePair(str: string): boolean;
|
974 |
|
975 | interface IsURLOptions {
|
976 | /**
|
977 | * @default ['http','https','ftp']
|
978 | */
|
979 | protocols?: string[];
|
980 | /**
|
981 | * @default true
|
982 | */
|
983 | require_tld?: boolean;
|
984 | /**
|
985 | * @default false
|
986 | */
|
987 | require_protocol?: boolean;
|
988 | /**
|
989 | * @default true
|
990 | */
|
991 | require_host?: boolean;
|
992 | /**
|
993 | * @default true
|
994 | */
|
995 | require_valid_protocol?: boolean;
|
996 | /**
|
997 | * @default false
|
998 | */
|
999 | allow_underscores?: boolean;
|
1000 | /**
|
1001 | * @default false
|
1002 | */
|
1003 | host_whitelist?: Array<string | RegExp>;
|
1004 | /**
|
1005 | * @default false
|
1006 | */
|
1007 | host_blacklist?: Array<string | RegExp>;
|
1008 | /**
|
1009 | * @default false
|
1010 | */
|
1011 | allow_trailing_dot?: boolean;
|
1012 | /**
|
1013 | * @default false
|
1014 | */
|
1015 | allow_protocol_relative_urls?: boolean;
|
1016 | /**
|
1017 | * @default false
|
1018 | */
|
1019 | disallow_auth?: boolean;
|
1020 | }
|
1021 |
|
1022 | /**
|
1023 | * Check if the string is an URL.
|
1024 | *
|
1025 | * @param [options] - Options
|
1026 | */
|
1027 | function isURL(str: string, options?: IsURLOptions): boolean;
|
1028 |
|
1029 | /**
|
1030 | * Check if the string is uppercase.
|
1031 | */
|
1032 | function isUppercase(str: string): boolean;
|
1033 |
|
1034 | /**
|
1035 | * Check if the string is a UUID (version 3, 4 or 5).
|
1036 | *
|
1037 | * @param [version="all"] - UUID version
|
1038 | */
|
1039 | function isUUID(str: string, version?: 3 | 4 | 5 | '3' | '4' | '5' | 'all'): boolean;
|
1040 |
|
1041 | /**
|
1042 | * Check if the string contains a mixture of full and half-width chars.
|
1043 | */
|
1044 | function isVariableWidth(str: string): boolean;
|
1045 |
|
1046 | /**
|
1047 | * Checks characters if they appear in the whitelist.
|
1048 | *
|
1049 | * @param chars - whitelist
|
1050 | */
|
1051 | function isWhitelisted(str: string, chars: string | string[]): boolean;
|
1052 |
|
1053 | /**
|
1054 | * Check if string matches the pattern.
|
1055 | *
|
1056 | * @param pattern - `/foo/i`
|
1057 | */
|
1058 | function matches(str: string, pattern: RegExp): boolean;
|
1059 | /**
|
1060 | * Check if string matches the pattern.
|
1061 | *
|
1062 | * @param pattern - `'foo'`
|
1063 | * @param [modifiers] - `'i'`
|
1064 | */
|
1065 | function matches(str: string, pattern: string, modifiers?: string): boolean;
|
1066 |
|
1067 | /**
|
1068 | * Check if the string is of type slug.
|
1069 | */
|
1070 | function isSlug(str: string): boolean;
|
1071 |
|
1072 | /******************
|
1073 | *** Sanitizers ***
|
1074 | ******************/
|
1075 |
|
1076 | /**
|
1077 | * Remove characters that appear in the blacklist.
|
1078 | *
|
1079 | * @param chars - The characters are used in a `RegExp` and so you will need to escape some chars, e.g. `blacklist(input, '\\[\\]')`.
|
1080 | */
|
1081 | function blacklist(input: string, chars: string): string;
|
1082 |
|
1083 | /**
|
1084 | * Replace `<`, `>`, `&`, `'`, `"` and `/` with HTML entities.
|
1085 | */
|
1086 | function escape(input: string): string;
|
1087 |
|
1088 | /**
|
1089 | * Replaces HTML encoded entities with `<`, `>`, `&`, `'`, `"` and `/`.
|
1090 | */
|
1091 | function unescape(input: string): string;
|
1092 |
|
1093 | /**
|
1094 | * Trim characters from the left-side of the input.
|
1095 | *
|
1096 | * @param [chars] - characters (defaults to whitespace)
|
1097 | */
|
1098 | function ltrim(input: string, chars?: string): string;
|
1099 |
|
1100 | interface NormalizeEmailOptions {
|
1101 | /**
|
1102 | * Transforms the local part (before the @ symbol) of all email addresses to lowercase.
|
1103 | * Please note that this may violate RFC 5321, which gives providers the possibility
|
1104 | * to treat the local part of email addresses in a case sensitive way
|
1105 | * (although in practice most - yet not all - providers don't).
|
1106 | * The domain part of the email address is always lowercased, as it's case insensitive per RFC 1035.
|
1107 | *
|
1108 | * @default true
|
1109 | */
|
1110 | all_lowercase?: boolean;
|
1111 | /**
|
1112 | * GMail addresses are known to be case-insensitive, so this switch allows lowercasing them even when `all_lowercase` is set to `false`.
|
1113 | * Please note that when `all_lowercase` is `true`, GMail addresses are lowercased regardless of the value of this setting.
|
1114 | *
|
1115 | * @default true
|
1116 | */
|
1117 | gmail_lowercase?: boolean;
|
1118 | /**
|
1119 | * Removes dots from the local part of the email address, as GMail ignores them
|
1120 | * (e.g. `"john.doe"` and `"johndoe"` are considered equal).
|
1121 | *
|
1122 | * @default true
|
1123 | */
|
1124 | gmail_remove_dots?: boolean;
|
1125 | /**
|
1126 | * Normalizes addresses by removing "sub-addresses", which is the part following a `"+"` sign
|
1127 | * (e.g. `"foo+bar@gmail.com"` becomes `"foo@gmail.com"`).
|
1128 | *
|
1129 | * @default true
|
1130 | */
|
1131 | gmail_remove_subaddress?: boolean;
|
1132 | /**
|
1133 | * Converts addresses with domain `@googlemail.com` to `@gmail.com`, as they're equivalent.
|
1134 | *
|
1135 | * @default true
|
1136 | */
|
1137 | gmail_convert_googlemaildotcom?: boolean;
|
1138 | /**
|
1139 | * Outlook.com addresses (including Windows Live and Hotmail) are known to be case-insensitive, so this switch allows lowercasing them even when `all_lowercase` is set to `false`.
|
1140 | * Please note that when `all_lowercase` is `true`, Outlook.com addresses are lowercased regardless of the value of this setting.
|
1141 | *
|
1142 | * @default true
|
1143 | */
|
1144 | outlookdotcom_lowercase?: boolean;
|
1145 | /**
|
1146 | * Normalizes addresses by removing "sub-addresses", which is the part following a `"+"` sign
|
1147 | * (e.g. `"foo+bar@outlook.com"` becomes `"foo@outlook.com"`).
|
1148 | *
|
1149 | * @default true
|
1150 | */
|
1151 | outlookdotcom_remove_subaddress?: boolean;
|
1152 | /**
|
1153 | * Yahoo Mail addresses are known to be case-insensitive, so this switch allows lowercasing them even when `all_lowercase` is set to `false`.
|
1154 | * Please note that when `all_lowercase` is `true`, Yahoo Mail addresses are lowercased regardless of the value of this setting.
|
1155 | *
|
1156 | * @default true
|
1157 | */
|
1158 | yahoo_lowercase?: boolean;
|
1159 | /**
|
1160 | * Normalizes addresses by removing "sub-addresses", which is the part following a `"-"` sign
|
1161 | * (e.g. `"foo-bar@yahoo.com"` becomes `"foo@yahoo.com"`).
|
1162 | *
|
1163 | * @default true
|
1164 | */
|
1165 | yahoo_remove_subaddress?: boolean;
|
1166 | /**
|
1167 | * iCloud addresses (including MobileMe) are known to be case-insensitive, so this switch allows lowercasing them even when `all_lowercase` is set to `false`.
|
1168 | * Please note that when `all_lowercase` is `true`, iCloud addresses are lowercased regardless of the value of this setting.
|
1169 | *
|
1170 | * @default true
|
1171 | */
|
1172 | icloud_lowercase?: boolean;
|
1173 | /**
|
1174 | * Normalizes addresses by removing "sub-addresses", which is the part following a `"+"` sign
|
1175 | * (e.g. `"foo+bar@icloud.com"` becomes `"foo@icloud.com"`).
|
1176 | *
|
1177 | * @default true
|
1178 | */
|
1179 | icloud_remove_subaddress?: boolean;
|
1180 | }
|
1181 |
|
1182 | /**
|
1183 | * Canonicalizes an email address. (This doesn't validate that the input is an email, if you want to validate the email use `isEmail` beforehand)
|
1184 | *
|
1185 | * @param [options] - Options
|
1186 | */
|
1187 | function normalizeEmail(email: string, options?: NormalizeEmailOptions): string | false;
|
1188 |
|
1189 | /**
|
1190 | * Trim characters from the right-side of the input.
|
1191 | *
|
1192 | * @param [chars] - characters (defaults to whitespace)
|
1193 | */
|
1194 | function rtrim(input: string, chars?: string): string;
|
1195 |
|
1196 | /**
|
1197 | * Remove characters with a numerical value < `32` and `127`, mostly control characters.
|
1198 | * Unicode-safe in JavaScript.
|
1199 | *
|
1200 | * @param [keep_new_lines=false] - if `true`, newline characters are preserved (`\n` and `\r`, hex `0xA` and `0xD`).
|
1201 | */
|
1202 | function stripLow(input: string, keep_new_lines?: boolean): string;
|
1203 |
|
1204 | /**
|
1205 | * Convert the input string to a boolean.
|
1206 | * Everything except for `'0'`, `'false'` and `''` returns `true`.
|
1207 | *
|
1208 | * @param [strict=false] - in `strict` mode, only `'1'` and `'true'` return `true`.
|
1209 | */
|
1210 | function toBoolean(input: string, strict?: boolean): boolean;
|
1211 |
|
1212 | /**
|
1213 | * Convert the input string to a `Date`, or `null` if the input is not a date.
|
1214 | */
|
1215 | function toDate(input: string): Date | null;
|
1216 |
|
1217 | /**
|
1218 | * Convert the input string to a float, or `NaN` if the input is not a float.
|
1219 | */
|
1220 | function toFloat(input: string): number;
|
1221 |
|
1222 | /**
|
1223 | * Convert the input string to an integer, or `NaN` if the input is not an integer.
|
1224 | *
|
1225 | * @param [radix=10] - radix or base (defaults to 10)
|
1226 | */
|
1227 | function toInt(input: string, radix?: number): number;
|
1228 |
|
1229 | /**
|
1230 | * Trim characters from both sides of the input.
|
1231 | *
|
1232 | * @param [chars] - characters (defaults to whitespace)
|
1233 | */
|
1234 | function trim(input: string, chars?: string): string;
|
1235 |
|
1236 | /**
|
1237 | * Remove characters that do not appear in the whitelist.
|
1238 | *
|
1239 | * @param chars - The characters are used in a `RegExp` and so you will need to escape some chars, e.g. `whitelist(input, '\\[\\]')`.
|
1240 | */
|
1241 | function whitelist(input: string, chars: string): string;
|
1242 |
|
1243 | /**
|
1244 | * Converts to string.
|
1245 | */
|
1246 | function toString(input: any): string;
|
1247 | }
|
1248 | export default validator;
|