UNPKG

39.9 kBTypeScriptView Raw
1import * as _isBoolean from "./lib/isBoolean";
2import * as _isEmail from "./lib/isEmail";
3import * as _isFQDN from "./lib/isFQDN";
4import * as _isIBAN from "./lib/isIBAN";
5import * as _isISO31661Alpha2 from "./lib/isISO31661Alpha2";
6import * as _isISO4217 from "./lib/isISO4217";
7import * as _isISO6391 from "./lib/isISO6391";
8import * as _isTaxID from "./lib/isTaxID";
9import * as _isURL from "./lib/isURL";
10
11declare namespace validator {
12 export const version: string;
13
14 /******************
15 *** Validators ***
16 ******************/
17
18 export interface ContainsOptions {
19 /**
20 * @default false
21 */
22 ignoreCase?: boolean | undefined;
23 /**
24 * @default 1
25 */
26 minOccurrences?: number | undefined;
27 }
28
29 /**
30 * Check if the string contains the seed.
31 *
32 * @param seed - Seed
33 */
34 export function contains(str: string, seed: any, options?: ContainsOptions): boolean;
35
36 /**
37 * Check if the string matches the comparison.
38 *
39 * @param comparison - String to compare
40 */
41 export function equals(str: string, comparison: string): boolean;
42
43 /**
44 * Check if the string is an ABA routing number for US bank account / cheque.
45 */
46 export function isAbaRouting(str: string): boolean;
47
48 /**
49 * Check if the string is a date that's after the specified date.
50 *
51 * @param [date] - Date string (defaults to now)
52 */
53 export function isAfter(str: string, date?: string): boolean;
54
55 export type AlphaLocale =
56 | "en-US"
57 | "bg-BG"
58 | "cs-CZ"
59 | "da-DK"
60 | "de-DE"
61 | "el-GR"
62 | "es-AR"
63 | "es-ES"
64 | "fr-FR"
65 | "it-IT"
66 | "nb-NO"
67 | "nl-NL"
68 | "nn-NO"
69 | "hu-HU"
70 | "pl-PL"
71 | "pt-PT"
72 | "ru-RU"
73 | "sl-SI"
74 | "sk-SK"
75 | "sr-RS@latin"
76 | "sr-RS"
77 | "sv-SE"
78 | "tr-TR"
79 | "uk-UA"
80 | "ku-IQ"
81 | "ar"
82 | "he"
83 | "fa-IR"
84 | "en-AU"
85 | "en-GB"
86 | "en-HK"
87 | "en-IN"
88 | "en-NZ"
89 | "en-ZA"
90 | "en-ZM"
91 | "ar-AE"
92 | "ar-BH"
93 | "ar-DZ"
94 | "ar-EG"
95 | "ar-IQ"
96 | "ar-JO"
97 | "ar-KW"
98 | "ar-LB"
99 | "ar-LY"
100 | "ar-MA"
101 | "ar-QM"
102 | "ar-QA"
103 | "ar-SA"
104 | "ar-SD"
105 | "ar-SY"
106 | "ar-TN"
107 | "ar-YE"
108 | "pt-BR"
109 | "pl-Pl";
110
111 export const isAlphaLocales: AlphaLocale[];
112
113 export interface IsAlphaOptions {
114 /**
115 * @default undefined
116 */
117 ignore?: string | RegExp | undefined;
118 }
119
120 /**
121 * Check if the string contains only letters (a-zA-Z).
122 *
123 * @param [locale] - AlphaLocale
124 * @param [options] - IsAlphaOptions
125 */
126 export function isAlpha(str: string, locale?: AlphaLocale, options?: IsAlphaOptions): boolean;
127
128 export type AlphanumericLocale =
129 | "en-US"
130 | "bg-BG"
131 | "cs-CZ"
132 | "da-DK"
133 | "de-DE"
134 | "el-GR"
135 | "es-AR"
136 | "es-ES"
137 | "fr-FR"
138 | "it-IT"
139 | "hu-HU"
140 | "nb-NO"
141 | "nl-NL"
142 | "nn-NO"
143 | "pl-PL"
144 | "pt-PT"
145 | "ru-RU"
146 | "sl-SI"
147 | "sk-SK"
148 | "sr-RS@latin"
149 | "sr-RS"
150 | "sv-SE"
151 | "tr-TR"
152 | "uk-UA"
153 | "ku-IQ"
154 | "ar"
155 | "he"
156 | "fa-IR"
157 | "en-AU"
158 | "en-GB"
159 | "en-HK"
160 | "en-IN"
161 | "en-NZ"
162 | "en-ZA"
163 | "en-ZM"
164 | "ar-AE"
165 | "ar-BH"
166 | "ar-DZ"
167 | "ar-EG"
168 | "ar-IQ"
169 | "ar-JO"
170 | "ar-KW"
171 | "ar-LB"
172 | "ar-LY"
173 | "ar-MA"
174 | "ar-QM"
175 | "ar-QA"
176 | "ar-SA"
177 | "ar-SD"
178 | "ar-SY"
179 | "ar-TN"
180 | "ar-YE"
181 | "pt-BR"
182 | "pl-Pl";
183
184 export const isAlphanumericLocales: AlphanumericLocale[];
185
186 export interface IsAlphanumericOptions {
187 /**
188 * @default undefined
189 */
190 ignore?: string | RegExp | undefined;
191 }
192
193 /**
194 * Check if the string contains only letters and numbers.
195 *
196 * @param [locale] - AlphanumericLocale
197 * @param [options] - IsAlphanumericOptions
198 */
199 export function isAlphanumeric(str: string, locale?: AlphanumericLocale, options?: IsAlphanumericOptions): boolean;
200
201 /**
202 * Check if the string contains ASCII chars only.
203 */
204 export function isAscii(str: string): boolean;
205
206 /**
207 * Check if a string is base32 encoded.
208 */
209 export function isBase32(str: string): boolean;
210 /**
211 * check if a string is base58 encoded
212 */
213 export function isBase58(str: string): boolean;
214
215 export interface IsBase64Options {
216 /**
217 * @default false
218 */
219 urlSafe?: boolean | undefined;
220 }
221
222 /**
223 * Check if a string is base64 encoded.
224 *
225 * @param [options] - Options
226 */
227 export function isBase64(str: string, options?: IsBase64Options): boolean;
228
229 /**
230 * Check if the string is a date that's before the specified date.
231 *
232 * @param [date] - Date string (defaults to now)
233 */
234 export function isBefore(str: string, date?: string): boolean;
235
236 export const isIBAN: typeof _isIBAN.default;
237 export const ibanLocales: typeof _isIBAN.locales;
238
239 /**
240 * Check if a string is a BIC (Bank Identification Code) or SWIFT code.
241 */
242 export function isBIC(str: string): boolean;
243
244 export const isBoolean: typeof _isBoolean.default;
245
246 export interface IsByteLengthOptions {
247 /**
248 * @default 0
249 */
250 min?: number | undefined;
251 /**
252 * @default undefined
253 */
254 max?: number | undefined;
255 }
256
257 /**
258 * Check if the string's length (in UTF-8 bytes) falls in a range.
259 *
260 * @param [options] - Options
261 */
262 export function isByteLength(str: string, options?: IsByteLengthOptions): boolean;
263
264 export interface IsCreditCardOptions {
265 /**
266 * @default undefined
267 */
268 provider?: "amex" | "dinersclub" | "discover" | "jcb" | "mastercard" | "unionpay" | "visa" | "";
269 }
270
271 /**
272 * Check if the string is a credit card.
273 */
274 export function isCreditCard(str: string, options?: IsCreditCardOptions): boolean;
275
276 export interface IsCurrencyOptions {
277 /**
278 * @default '$'
279 */
280 symbol?: string | undefined;
281 /**
282 * @default false
283 */
284 require_symbol?: boolean | undefined;
285 /**
286 * @default false
287 */
288 allow_space_after_symbol?: boolean | undefined;
289 /**
290 * @default false
291 */
292 symbol_after_digits?: boolean | undefined;
293 /**
294 * @default true
295 */
296 allow_negatives?: boolean | undefined;
297 /**
298 * @default false
299 */
300 parens_for_negatives?: boolean | undefined;
301 /**
302 * @default false
303 */
304 negative_sign_before_digits?: boolean | undefined;
305 /**
306 * @default false
307 */
308 negative_sign_after_digits?: boolean | undefined;
309 /**
310 * @default false
311 */
312 allow_negative_sign_placeholder?: boolean | undefined;
313 /**
314 * @default ','
315 */
316 thousands_separator?: string | undefined;
317 /**
318 * @default '.'
319 */
320 decimal_separator?: string | undefined;
321 /**
322 * @default true
323 */
324 allow_decimal?: boolean | undefined;
325 /**
326 * @default false
327 */
328 require_decimal?: boolean | undefined;
329 /**
330 * 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]`.
331 *
332 * @default [2]
333 */
334 digits_after_decimal?: number[] | undefined;
335 /**
336 * @default false
337 */
338 allow_space_after_digits?: boolean | undefined;
339 }
340
341 /**
342 * Check if the string is a valid currency amount.
343 *
344 * @param [options] - Options
345 */
346 export function isCurrency(str: string, options?: IsCurrencyOptions): boolean;
347
348 /**
349 * Check if the string is an [Ethereum](https://ethereum.org/) address using basic regex. Does not validate address checksums.
350 */
351 export function isEthereumAddress(str: string): boolean;
352
353 /**
354 * Check if the string is a valid BTC address.
355 */
356 export function isBtcAddress(str: string): boolean;
357
358 /**
359 * Check if the string is a [data uri format](https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs).
360 */
361 export function isDataURI(str: string): boolean;
362
363 export interface IsDateOptions {
364 /**
365 * @default false
366 */
367 format?: string | undefined;
368 /**
369 * If strictMode is set to true,
370 * the validator will reject inputs different from format.
371 *
372 * @default false
373 */
374 strictMode?: boolean | undefined;
375 /**
376 * `delimiters` is an array of allowed date delimiters
377 *
378 * @default ['/', '-']
379 */
380 delimiters?: string[] | undefined;
381 }
382
383 /**
384 * Check if the string is a valid date.
385 */
386 export function isDate(str: string, options?: IsDateOptions): boolean;
387
388 export type DecimalLocale = FloatLocale;
389
390 export interface IsDecimalOptions {
391 /**
392 * @default false
393 */
394 force_decimal?: boolean | undefined;
395 /**
396 * `decimal_digits` is given as a range like `'1,3'`,
397 * a specific value like `'3'` or min like `'1,'`
398 *
399 * @default '1,'
400 */
401 decimal_digits?: string | undefined;
402 /**
403 * DecimalLocale
404 *
405 * @default 'en-US'
406 */
407 locale?: DecimalLocale | undefined;
408 }
409
410 /**
411 * Check if the string represents a decimal number,
412 * such as `0.1`, `.3`, `1.1`, `1.00003`, `4.0` etc.
413 *
414 * @param [options] - Options
415 */
416 export function isDecimal(str: string, options?: IsDecimalOptions): boolean;
417
418 /**
419 * Check if the string is a number that's divisible by another.
420 *
421 * @param number - Divider number
422 */
423 export function isDivisibleBy(str: string, number: number): boolean;
424
425 export type IsEmailOptions = _isEmail.IsEmailOptions;
426 export const isEmail: typeof _isEmail.default;
427
428 /**
429 * check if the string is a [Magnet URI format][Mailto URI Format].<br/><br/>`options` is an object of validating emails inside the URI (check `isEmail`s options for details).
430 * @param str
431 * @param [options]
432 */
433 export function isMailtoURI(str: string, options?: IsEmailOptions): boolean;
434
435 export interface IsEmptyOptions {
436 /**
437 * @default false
438 */
439 ignore_whitespace?: boolean | undefined;
440 }
441
442 /**
443 * Check if the string has a length of zero.
444 *
445 * @param [options] - Options
446 */
447 export function isEmpty(str: string, options?: IsEmptyOptions): boolean;
448
449 export type FloatLocale =
450 | "en-US"
451 | "ar"
452 | "en-AU"
453 | "en-GB"
454 | "en-HK"
455 | "en-IN"
456 | "en-NZ"
457 | "en-ZA"
458 | "en-ZM"
459 | "ar-AE"
460 | "ar-BH"
461 | "ar-DZ"
462 | "ar-EG"
463 | "ar-IQ"
464 | "ar-JO"
465 | "ar-KW"
466 | "ar-LB"
467 | "ar-LY"
468 | "ar-MA"
469 | "ar-QM"
470 | "ar-QA"
471 | "ar-SA"
472 | "ar-SD"
473 | "ar-SY"
474 | "ar-TN"
475 | "ar-YE"
476 | "bg-BG"
477 | "cs-CZ"
478 | "da-DK"
479 | "de-DE"
480 | "el-GR"
481 | "es-ES"
482 | "fr-FR"
483 | "it-IT"
484 | "ku-IQ"
485 | "hu-HU"
486 | "nb-NO"
487 | "nn-NO"
488 | "nl-NL"
489 | "pl-PL"
490 | "pt-PT"
491 | "ru-RU"
492 | "sl-SI"
493 | "sr-RS@latin"
494 | "sr-RS"
495 | "sv-SE"
496 | "tr-TR"
497 | "uk-UA"
498 | "pt-BR"
499 | "pl-Pl";
500
501 export const isFloatLocales: FloatLocale[];
502
503 export interface IsFloatOptions {
504 /**
505 * less or equal
506 */
507 min?: number | undefined;
508 /**
509 * greater or equal
510 */
511 max?: number | undefined;
512 /**
513 * greater than
514 */
515 gt?: number | undefined;
516 /**
517 * less than
518 */
519 lt?: number | undefined;
520 /**
521 * FloatLocale
522 */
523 locale?: FloatLocale | undefined;
524 }
525
526 /**
527 * Check if the string is a float.
528 *
529 * @param [options] - Options
530 */
531 export function isFloat(str: string, options?: IsFloatOptions): boolean;
532
533 export type IsFQDNOptions = _isFQDN.IsFQDNOptions;
534 export const isFQDN: typeof _isFQDN.default;
535
536 /**
537 * Check if the string contains any full-width chars.
538 */
539 export function isFullWidth(str: string): boolean;
540
541 /**
542 * Check if the string contains any half-width chars.
543 */
544 export function isHalfWidth(str: string): boolean;
545
546 export type HashAlgorithm =
547 | "md4"
548 | "md5"
549 | "sha1"
550 | "sha256"
551 | "sha384"
552 | "sha512"
553 | "ripemd128"
554 | "ripemd160"
555 | "tiger128"
556 | "tiger160"
557 | "tiger192"
558 | "crc32"
559 | "crc32b";
560
561 /**
562 * Check if the string is a hash of export type algorithm.
563 *
564 * @param algorithm - HashAlgorithm
565 */
566 export function isHash(str: string, algorithm: HashAlgorithm): boolean;
567
568 /**
569 * Check if the string is a hexadecimal number.
570 */
571 export function isHexadecimal(str: string): boolean;
572
573 /**
574 * Check if the string is a hexadecimal color.
575 */
576 export function isHexColor(str: string): boolean;
577
578 /**
579 * Check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on CSS Colors Level 4 specification.
580 * Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: hsl(200grad+.1%62%/1)).
581 */
582 export function isHSL(str: string): boolean;
583
584 /**
585 * Check if the string is a rgb or rgba color.
586 *
587 * @param [includePercentValues=true] - If you don't want to allow to set rgb or rgba values with percents, like rgb(5%,5%,5%), or rgba(90%,90%,90%,.3), then set it to false. (defaults to true)
588 */
589 export function isRgbColor(str: string, includePercentValues?: boolean): boolean;
590
591 export type IdentityCardLocale =
592 | "ar-LY"
593 | "ar-TN"
594 | "ES"
595 | "FI"
596 | "he-IL"
597 | "IN"
598 | "IR"
599 | "IT"
600 | "LK"
601 | "NO"
602 | "PL"
603 | "TH"
604 | "zh-CN"
605 | "zh-HK"
606 | "zh-TW";
607
608 /**
609 * Check if the string is a valid identity card code.
610 *
611 * @param [locale="any"] - IdentityCardLocale
612 */
613 export function isIdentityCard(str: string, locale?: "any" | IdentityCardLocale): boolean;
614
615 export interface IsIMEIOptions {
616 /**
617 * This value is `false` by default. Set to `true` to allow IMEI with hyphens.
618 */
619 allow_hyphens?: boolean | undefined;
620 }
621
622 /**
623 * Check if the string is a valid IMEI.
624 * Non-hyphenated (`###############`) only is supported by default.
625 * Use the `options` param to enable hyphenated (`##-######-######-#`) support.
626 *
627 * @param [options] - Options
628 */
629 export function isIMEI(str: string, options?: IsIMEIOptions): boolean;
630
631 /**
632 * Check if the string is in a array of allowed values.
633 *
634 * @param values - Allowed values.
635 */
636 export function isIn(str: string, values: any[]): boolean;
637
638 export interface IsIntOptions {
639 /**
640 * to check the integer min boundary
641 */
642 min?: number | undefined;
643 /**
644 * to check the integer max boundary
645 */
646 max?: number | undefined;
647 /**
648 * if `false`, will disallow integer values with leading zeroes
649 * @default true
650 */
651 allow_leading_zeroes?: boolean | undefined;
652 /**
653 * enforce integers being greater than the value provided
654 */
655 lt?: number | undefined;
656 /**
657 * enforce integers being less than the value provided
658 */
659 gt?: number | undefined;
660 }
661
662 /**
663 * Check if the string is an integer.
664 *
665 * @param [options] - Options
666 */
667 export function isInt(str: string, options?: IsIntOptions): boolean;
668
669 export type IPVersion = "4" | "6" | 4 | 6;
670
671 /**
672 * Check if the string is an IP (version 4 or 6).
673 *
674 * @param [version] - IP Version
675 */
676 export function isIP(str: string, version?: IPVersion): boolean;
677
678 /**
679 * Check if the string is an IP Range (version 4 or 6).
680 */
681 export function isIPRange(str: string, version?: IPVersion): boolean;
682
683 export type ISBNVersion = "10" | "13" | 10 | 13;
684
685 /**
686 * Check if the string is an ISBN (version 10 or 13).
687 *
688 * @param [version] - ISBN Version
689 */
690 export function isISBN(str: string, version?: ISBNVersion): boolean;
691
692 /**
693 * Check if the string is an EAN (European Article Number).
694 */
695 export function isEAN(str: string): boolean;
696
697 /**
698 * Check if the string is an [ISIN](https://en.wikipedia.org/wiki/International_Securities_Identification_Number) (stock/security identifier).
699 */
700 export function isISIN(str: string): boolean;
701
702 export const isISO31661Alpha2: typeof _isISO31661Alpha2.default;
703
704 /**
705 * 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.
706 */
707 export function isISO31661Alpha3(str: string): boolean;
708
709 /**
710 * check if the string is a valid [ISO 6346](https://en.wikipedia.org/wiki/ISO_6346) shipping container identification.
711 * @param str
712 */
713 export function isISO6346(str: string): boolean;
714
715 /**
716 * alias for `isISO6346`, check if the string is a valid [ISO 6346](https://en.wikipedia.org/wiki/ISO_6346) shipping container identification.
717 */
718 export const isFreightContainerID: typeof isISO6346;
719
720 /**
721 * Check if the string is a valid [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) officially assigned language code.
722 */
723 export const isISO6391: typeof _isISO6391.default;
724
725 export interface IsISO8601Options {
726 /**
727 * If `strict` is `true`, performs additional checks for valid dates,
728 * e.g. invalidates dates like `2009-02-29`.
729 *
730 * @default false
731 */
732 strict?: boolean | undefined;
733 /**
734 * If `strictSeparator` is true, date strings with date and time separated
735 * by anything other than a T will be invalid
736 */
737 strictSeparator?: boolean | undefined;
738 }
739
740 /**
741 * Check if the string is a valid [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date.
742 *
743 * @param [options] - Options
744 */
745 export function isISO8601(str: string, options?: IsISO8601Options): boolean;
746
747 export interface IsISSNOptions {
748 /**
749 * If `case_sensitive` is `true`, ISSNs with a lowercase `x` as the check digit are rejected.
750 *
751 * @default false
752 */
753 case_sensitive?: boolean | undefined;
754 /**
755 * @default false
756 */
757 require_hyphen?: boolean | undefined;
758 }
759
760 /**
761 * Check if the string is an [ISSN](https://en.wikipedia.org/wiki/International_Standard_Serial_Number).
762 *
763 * @param [options] - Options
764 */
765 export function isISSN(str: string, options?: IsISSNOptions): boolean;
766
767 export const isISO4217: typeof _isISO4217.default;
768
769 /**
770 * Check if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code).
771 */
772 export function isISRC(str: string): boolean;
773
774 /**
775 * Check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date.
776 */
777 export function isRFC3339(str: string): boolean;
778
779 /**
780 * Check if the string is valid JSON (note: uses `JSON.parse`).
781 */
782 export function isJSON(str: string): boolean;
783
784 /**
785 * Check if the string is valid JWT token.
786 */
787 export function isJWT(str: string): boolean;
788
789 /**
790 * Check if the string is a valid latitude-longitude coordinate in the format:
791 *
792 * `lat,long` or `lat, long`.
793 */
794 export function isLatLong(str: string): boolean;
795
796 export interface IsLengthOptions {
797 /**
798 * @default 0
799 */
800 min?: number | undefined;
801 /**
802 * @default undefined
803 */
804 max?: number | undefined;
805 }
806
807 /**
808 * Check if the string's length falls in a range.
809 *
810 * Note: this export function takes into account surrogate pairs.
811 *
812 * @param [options] - Options
813 */
814 export function isLength(str: string, options?: IsLengthOptions): boolean;
815
816 export type LicensePlateLocale =
817 | "cs-CZ"
818 | "de-DE"
819 | "de-LI"
820 | "en-IN"
821 | "es-AR"
822 | "hu-HU"
823 | "pt-BR"
824 | "pt-PT"
825 | "sq-AL"
826 | "sv-SE"
827 | "en-PK"
828 | "any";
829
830 /**
831 * Check if the string matches the format of a country's license plate.
832 */
833 export function isLicensePlate(str: string, locale: LicensePlateLocale): boolean;
834 export function isLicensePlate(str: string, locale: string): unknown;
835
836 /**
837 * Check if the string is a locale.
838 */
839 export function isLocale(str: string): boolean;
840
841 /**
842 * Check if the string is lowercase.
843 */
844 export function isLowercase(str: string): boolean;
845
846 export interface IsMACAddressOptions {
847 /**
848 * If `no_colons` is `true`, the validator will allow MAC addresses without the colons.
849 * Also, it allows the use of hyphens or spaces.
850 *
851 * e.g. `01 02 03 04 05 ab` or `01-02-03-04-05-ab`.
852 *
853 * @default false
854 * @deprecated use no_separators instead
855 */
856 no_colons?: boolean | undefined;
857 /**
858 * If `no_separators` is `true`, the validator will allow MAC addresses without the colons.
859 * Also, it allows the use of hyphens or spaces.
860 *
861 * e.g. `01 02 03 04 05 ab` or `01-02-03-04-05-ab`.
862 *
863 * @default false
864 */
865 no_separators?: boolean | undefined;
866 /**
867 * Setting `eui` allows for validation against EUI-48 or EUI-64 instead of both.
868 */
869 eui?: "48" | "64" | undefined;
870 }
871
872 /**
873 * Check if the string passes the [Luhn algorithm check](https://en.m.wikipedia.org/wiki/Luhn_algorithm).
874 */
875 export function isLuhnNumber(str: string): boolean;
876
877 /**
878 * Check if the string is a MAC address.
879 *
880 * @param [options] - Options
881 */
882 export function isMACAddress(str: string, options?: IsMACAddressOptions): boolean;
883
884 /**
885 * Check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme).
886 */
887 export function isMagnetURI(str: string): boolean;
888
889 /**
890 * Check if the string is a MD5 hash.
891 */
892 export function isMD5(str: string): boolean;
893
894 /**
895 * Check if the string matches to a valid [MIME export type](https://en.wikipedia.org/wiki/Media_export type) format.
896 */
897 export function isMimeType(str: string): boolean;
898
899 export type MobilePhoneLocale = PhoneLocale | PhoneLocaleAlias;
900 export type PhoneLocale =
901 | "am-AM"
902 | "ar-AE"
903 | "ar-BH"
904 | "ar-DZ"
905 | "ar-LB"
906 | "ar-EG"
907 | "ar-IQ"
908 | "ar-JO"
909 | "ar-KW"
910 | "ar-LY"
911 | "ar-MA"
912 | "ar-OM"
913 | "ar-SA"
914 | "ar-SY"
915 | "ar-TN"
916 | "az-AZ"
917 | "bs-BA"
918 | "be-BY"
919 | "bg-BG"
920 | "bn-BD"
921 | "ca-AD"
922 | "cs-CZ"
923 | "da-DK"
924 | "de-DE"
925 | "de-AT"
926 | "de-CH"
927 | "de-LU"
928 | "el-GR"
929 | "en-AU"
930 | "en-GB"
931 | "en-GG"
932 | "en-GH"
933 | "en-HK"
934 | "en-MO"
935 | "en-IE"
936 | "en-IN"
937 | "en-KE"
938 | "en-MT"
939 | "en-MU"
940 | "en-NG"
941 | "en-NZ"
942 | "en-PK"
943 | "en-PH"
944 | "en-RW"
945 | "en-SG"
946 | "en-SL"
947 | "en-TZ"
948 | "en-UG"
949 | "en-US"
950 | "en-ZA"
951 | "en-ZM"
952 | "en-ZW"
953 | "es-AR"
954 | "es-BO"
955 | "es-CO"
956 | "es-CL"
957 | "es-CR"
958 | "es-DO"
959 | "es-HN"
960 | "es-EC"
961 | "es-ES"
962 | "es-PE"
963 | "es-MX"
964 | "es-PA"
965 | "es-PY"
966 | "es-UY"
967 | "es-VE"
968 | "et-EE"
969 | "fa-IR"
970 | "fi-FI"
971 | "fj-FJ"
972 | "fo-FO"
973 | "fr-FR"
974 | "fr-GF"
975 | "fr-GP"
976 | "fr-MQ"
977 | "fr-RE"
978 | "he-IL"
979 | "hu-HU"
980 | "id-ID"
981 | "it-IT"
982 | "it-SM"
983 | "ja-JP"
984 | "ka-GE"
985 | "kk-KZ"
986 | "kl-GL"
987 | "ko-KR"
988 | "lt-LT"
989 | "lv-LV"
990 | "ms-MY"
991 | "mz-MZ"
992 | "nb-NO"
993 | "ne-NP"
994 | "nl-BE"
995 | "nl-NL"
996 | "nn-NO"
997 | "pl-PL"
998 | "pt-BR"
999 | "pt-PT"
1000 | "pt-AO"
1001 | "ro-RO"
1002 | "ru-RU"
1003 | "si-LK"
1004 | "sl-SI"
1005 | "sk-SK"
1006 | "sq-AL"
1007 | "sr-RS"
1008 | "sv-SE"
1009 | "th-TH"
1010 | "tr-TR"
1011 | "uk-UA"
1012 | "uz-UZ"
1013 | "vi-VN"
1014 | "zh-CN"
1015 | "zh-TW";
1016 export type PhoneLocaleAlias = "en-CA" | "fr-CA" | "fr-BE" | "zh-HK" | "zh-MO" | "ga-IE" | "fr-CH" | "it-CH";
1017
1018 export const isMobilePhoneLocales: MobilePhoneLocale[];
1019
1020 export interface IsMobilePhoneOptions {
1021 /**
1022 * If this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`.
1023 *
1024 * @default false
1025 */
1026 strictMode?: boolean | undefined;
1027 }
1028
1029 /**
1030 * Check if the string is a mobile phone number.
1031 *
1032 * @param [locale] - MobilePhoneLocale(s)
1033 * @param [options] - Options
1034 */
1035 export function isMobilePhone(
1036 str: string,
1037 locale?: "any" | MobilePhoneLocale | MobilePhoneLocale[],
1038 options?: IsMobilePhoneOptions,
1039 ): boolean;
1040
1041 /**
1042 * Check if the string is a valid hex-encoded representation of a [MongoDB ObjectId](http://docs.mongodb.org/manual/reference/object-id/).
1043 */
1044 export function isMongoId(str: string): boolean;
1045
1046 /**
1047 * Check if the string contains one or more multibyte chars.
1048 */
1049 export function isMultibyte(str: string): boolean;
1050
1051 export interface IsNumericOptions {
1052 /**
1053 * If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).
1054 *
1055 * @default false
1056 */
1057 no_symbols?: boolean | undefined;
1058 locale?: AlphaLocale | undefined;
1059 }
1060
1061 /**
1062 * Check if the string contains only numbers.
1063 *
1064 * @param [options] - Options
1065 */
1066 export function isNumeric(str: string, options?: IsNumericOptions): boolean;
1067
1068 /**
1069 * Check if the string is a valid octal number.
1070 */
1071 export function isOctal(str: string): boolean;
1072
1073 /**
1074 * Check if the string is a valid passport number relative to a specific country code.
1075 *
1076 * @param [countryCode] - Country code
1077 */
1078 export function isPassportNumber(str: string, countryCode?: string): boolean;
1079
1080 /**
1081 * Check if the string is a valid port number.
1082 */
1083 export function isPort(str: string): boolean;
1084
1085 export type PostalCodeLocale =
1086 | "AD"
1087 | "AT"
1088 | "AU"
1089 | "BE"
1090 | "BG"
1091 | "BR"
1092 | "CA"
1093 | "CH"
1094 | "CN"
1095 | "CZ"
1096 | "DE"
1097 | "DK"
1098 | "DZ"
1099 | "EE"
1100 | "ES"
1101 | "FI"
1102 | "FR"
1103 | "GB"
1104 | "GR"
1105 | "HR"
1106 | "HU"
1107 | "ID"
1108 | "IE"
1109 | "IL"
1110 | "IN"
1111 | "IR"
1112 | "IS"
1113 | "IT"
1114 | "JP"
1115 | "KE"
1116 | "KR"
1117 | "LI"
1118 | "LT"
1119 | "LU"
1120 | "LV"
1121 | "MX"
1122 | "MT"
1123 | "NL"
1124 | "NO"
1125 | "NZ"
1126 | "PL"
1127 | "PR"
1128 | "PT"
1129 | "RO"
1130 | "RU"
1131 | "SA"
1132 | "SE"
1133 | "SI"
1134 | "SK"
1135 | "TN"
1136 | "TW"
1137 | "UA"
1138 | "US"
1139 | "ZA"
1140 | "ZM";
1141
1142 export const isPostalCodeLocales: PostalCodeLocale[];
1143
1144 /**
1145 * Check if the string is a postal code
1146 *
1147 * @param locale - PostalCodeLocale
1148 */
1149 export function isPostalCode(str: string, locale: "any" | PostalCodeLocale): boolean;
1150
1151 /**
1152 * Check if the string is a Semantic Versioning Specification (SemVer).
1153 */
1154 export function isSemVer(str: string): boolean;
1155
1156 /**
1157 * Check if string is considered a strong password. Allows options to be added
1158 */
1159
1160 export interface StrongPasswordOptions {
1161 minLength?: number | undefined;
1162 minLowercase?: number | undefined;
1163 minUppercase?: number | undefined;
1164 minNumbers?: number | undefined;
1165 minSymbols?: number | undefined;
1166 returnScore?: boolean | undefined;
1167 pointsPerUnique?: number | undefined;
1168 pointsPerRepeat?: number | undefined;
1169 pointsForContainingLower?: number | undefined;
1170 pointsForContainingUpper?: number | undefined;
1171 pointsForContainingNumber?: number | undefined;
1172 pointsForContainingSymbol?: number | undefined;
1173 }
1174
1175 export function isStrongPassword(
1176 str: string,
1177 options?: StrongPasswordOptions & { returnScore?: false | undefined },
1178 ): boolean;
1179 export function isStrongPassword(str: string, options: StrongPasswordOptions & { returnScore: true }): number;
1180
1181 /**
1182 * Check if the string contains any surrogate pairs chars.
1183 */
1184 export function isSurrogatePair(str: string): boolean;
1185
1186 export interface IsTimeOptions {
1187 /**
1188 * 'hour24' will validate hours in 24 format and 'hour12' will validate hours in 12 format.
1189 * @default 'hour24'
1190 */
1191 hourFormat?: "hour12" | "hour24";
1192 /**
1193 * 'default' will validate HH:MM format, 'withSeconds' will validate the HH:MM:SS format
1194 *
1195 * @default 'default'
1196 */
1197 mode?: "default" | "withSeconds";
1198 }
1199
1200 /**
1201 * Check if the string is a valid time.
1202 */
1203 export function isTime(str: string, options?: IsTimeOptions): boolean;
1204
1205 export const isURL: typeof _isURL.default;
1206 export type IsURLOptions = _isURL.IsURLOptions;
1207
1208 export const isTaxID: typeof _isTaxID.default;
1209
1210 /**
1211 * Check if the string is uppercase.
1212 */
1213 export function isUppercase(str: string): boolean;
1214
1215 export type UUIDVersion = "1" | "2" | "3" | "4" | "5" | "7" | "all" | 1 | 2 | 3 | 4 | 5 | 7;
1216 /**
1217 * Check if the string is a UUID (version 1, 2, 3, 4, 5 or 7).
1218 *
1219 * @param [version="all"] - UUID version
1220 */
1221 export function isUUID(str: string, version?: UUIDVersion): boolean;
1222
1223 /**
1224 * Check if the string contains a mixture of full and half-width chars.
1225 */
1226 export function isVariableWidth(str: string): boolean;
1227
1228 /**
1229 * Checks that the string is a [valid VAT number
1230 */
1231 export function isVAT(str: string, countryCode: string): boolean;
1232
1233 /**
1234 * Checks characters if they appear in the whitelist.
1235 *
1236 * @param chars - whitelist
1237 */
1238 export function isWhitelisted(str: string, chars: string | string[]): boolean;
1239
1240 /**
1241 * Check if string matches the pattern.
1242 *
1243 * @param pattern - `/foo/i`
1244 */
1245 export function matches(str: string, pattern: RegExp): boolean;
1246 /**
1247 * Check if string matches the pattern.
1248 *
1249 * @param pattern - `'foo'`
1250 * @param [modifiers] - `'i'`
1251 */
1252 export function matches(str: string, pattern: string, modifiers?: string): boolean;
1253
1254 /**
1255 * Check if the string is of export type slug.
1256 */
1257 export function isSlug(str: string): boolean;
1258
1259 /******************
1260 *** Sanitizers ***
1261 ******************/
1262
1263 /**
1264 * Remove characters that appear in the blacklist.
1265 *
1266 * @param chars - The characters are used in a `RegExp` and so you will need to escape some chars, e.g. `blacklist(input, '\\[\\]')`.
1267 */
1268 export function blacklist(input: string, chars: string): string;
1269
1270 /**
1271 * Replace `<`, `>`, `&`, `'`, `"` and `/` with HTML entities.
1272 */
1273 export function escape(input: string): string;
1274
1275 /**
1276 * Replaces HTML encoded entities with `<`, `>`, `&`, `'`, `"` and `/`.
1277 */
1278 export function unescape(input: string): string;
1279
1280 /**
1281 * Trim characters from the left-side of the input.
1282 *
1283 * @param [chars] - characters (defaults to whitespace)
1284 */
1285 export function ltrim(input: string, chars?: string): string;
1286
1287 export interface NormalizeEmailOptions {
1288 /**
1289 * Transforms the local part (before the @ symbol) of all email addresses to lowercase.
1290 * Please note that this may violate RFC 5321, which gives providers the possibility
1291 * to treat the local part of email addresses in a case sensitive way
1292 * (although in practice most - yet not all - providers don't).
1293 * The domain part of the email address is always lowercased, as it's case insensitive per RFC 1035.
1294 *
1295 * @default true
1296 */
1297 all_lowercase?: boolean | undefined;
1298 /**
1299 * GMail addresses are known to be case-insensitive, so this switch allows lowercasing them even when `all_lowercase` is set to `false`.
1300 * Please note that when `all_lowercase` is `true`, GMail addresses are lowercased regardless of the value of this setting.
1301 *
1302 * @default true
1303 */
1304 gmail_lowercase?: boolean | undefined;
1305 /**
1306 * Removes dots from the local part of the email address, as GMail ignores them
1307 * (e.g. `"john.doe"` and `"johndoe"` are considered equal).
1308 *
1309 * @default true
1310 */
1311 gmail_remove_dots?: boolean | undefined;
1312 /**
1313 * Normalizes addresses by removing "sub-addresses", which is the part following a `"+"` sign
1314 * (e.g. `"foo+bar@gmail.com"` becomes `"foo@gmail.com"`).
1315 *
1316 * @default true
1317 */
1318 gmail_remove_subaddress?: boolean | undefined;
1319 /**
1320 * Converts addresses with domain `@googlemail.com` to `@gmail.com`, as they're equivalent.
1321 *
1322 * @default true
1323 */
1324 gmail_convert_googlemaildotcom?: boolean | undefined;
1325 /**
1326 * 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`.
1327 * Please note that when `all_lowercase` is `true`, Outlook.com addresses are lowercased regardless of the value of this setting.
1328 *
1329 * @default true
1330 */
1331 outlookdotcom_lowercase?: boolean | undefined;
1332 /**
1333 * Normalizes addresses by removing "sub-addresses", which is the part following a `"+"` sign
1334 * (e.g. `"foo+bar@outlook.com"` becomes `"foo@outlook.com"`).
1335 *
1336 * @default true
1337 */
1338 outlookdotcom_remove_subaddress?: boolean | undefined;
1339 /**
1340 * Yahoo Mail addresses are known to be case-insensitive, so this switch allows lowercasing them even when `all_lowercase` is set to `false`.
1341 * Please note that when `all_lowercase` is `true`, Yahoo Mail addresses are lowercased regardless of the value of this setting.
1342 *
1343 * @default true
1344 */
1345 yahoo_lowercase?: boolean | undefined;
1346 /**
1347 * Normalizes addresses by removing "sub-addresses", which is the part following a `"-"` sign
1348 * (e.g. `"foo-bar@yahoo.com"` becomes `"foo@yahoo.com"`).
1349 *
1350 * @default true
1351 */
1352 yahoo_remove_subaddress?: boolean | undefined;
1353 /**
1354 * iCloud addresses (including MobileMe) are known to be case-insensitive, so this switch allows lowercasing them even when `all_lowercase` is set to `false`.
1355 * Please note that when `all_lowercase` is `true`, iCloud addresses are lowercased regardless of the value of this setting.
1356 *
1357 * @default true
1358 */
1359 icloud_lowercase?: boolean | undefined;
1360 /**
1361 * Normalizes addresses by removing "sub-addresses", which is the part following a `"+"` sign
1362 * (e.g. `"foo+bar@icloud.com"` becomes `"foo@icloud.com"`).
1363 *
1364 * @default true
1365 */
1366 icloud_remove_subaddress?: boolean | undefined;
1367 }
1368
1369 /**
1370 * Canonicalizes an email address. (This doesn't validate that the input is an email, if you want to validate the email use `isEmail` beforehand)
1371 *
1372 * @param [options] - Options
1373 */
1374 export function normalizeEmail(email: string, options?: NormalizeEmailOptions): string | false;
1375
1376 /**
1377 * Trim characters from the right-side of the input.
1378 *
1379 * @param [chars] - characters (defaults to whitespace)
1380 */
1381 export function rtrim(input: string, chars?: string): string;
1382
1383 /**
1384 * Remove characters with a numerical value < `32` and `127`, mostly control characters.
1385 * Unicode-safe in JavaScript.
1386 *
1387 * @param [keep_new_lines=false] - if `true`, newline characters are preserved (`\n` and `\r`, hex `0xA` and `0xD`).
1388 */
1389 export function stripLow(input: string, keep_new_lines?: boolean): string;
1390
1391 /**
1392 * Convert the input string to a boolean.
1393 * Everything except for `'0'`, `'false'` and `''` returns `true`.
1394 *
1395 * @param [strict=false] - in `strict` mode, only `'1'` and `'true'` return `true`.
1396 */
1397 export function toBoolean(input: string, strict?: boolean): boolean;
1398
1399 /**
1400 * Convert the input string to a `Date`, or `null` if the input is not a date.
1401 */
1402 export function toDate(input: string): Date | null;
1403
1404 /**
1405 * Convert the input string to a float, or `NaN` if the input is not a float.
1406 */
1407 export function toFloat(input: string): number;
1408
1409 /**
1410 * Convert the input string to an integer, or `NaN` if the input is not an integer.
1411 *
1412 * @param [radix=10] - radix or base (defaults to 10)
1413 */
1414 export function toInt(input: string, radix?: number): number;
1415
1416 /**
1417 * Trim characters from both sides of the input.
1418 *
1419 * @param [chars] - characters (defaults to whitespace)
1420 */
1421 export function trim(input: string, chars?: string): string;
1422
1423 /**
1424 * Remove characters that do not appear in the whitelist.
1425 *
1426 * @param chars - The characters are used in a `RegExp` and so you will need to escape some chars, e.g. `whitelist(input, '\\[\\]')`.
1427 */
1428 export function whitelist(input: string, chars: string): string;
1429
1430 /**
1431 * Converts to string.
1432 */
1433 export function toString(input: any): string;
1434
1435 export const _default: typeof validator;
1436
1437 export { _default as default };
1438}
1439
1440// eslint-disable-next-line @definitelytyped/export-just-namespace
1441export = validator;
1442
1443export as namespace validator;