validator.d.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // Type definitions for validator.js v3.22.1
  2. // Project: https://github.com/chriso/validator.js
  3. // Definitions by: tgfjt <https://github.com/tgfjt>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5. // options for #isURL
  6. interface IURLoptions {
  7. protocols?: string[]
  8. require_tld?: boolean
  9. require_protocol?: boolean
  10. allow_underscores?: boolean
  11. }
  12. // options for isFQDN
  13. interface IFQDNoptions {
  14. require_tld?: boolean
  15. allow_underscores?: boolean
  16. }
  17. // options for normalizeEmail
  18. interface IEmailoptions {
  19. lowercase?: boolean
  20. }
  21. // callback type for #extend
  22. interface IExtendCallback {
  23. (argv: string): any
  24. }
  25. // return function for #extend
  26. interface IExtendFunc {
  27. (argv: string): boolean
  28. }
  29. interface IValidatorStatic {
  30. // add your own validators
  31. extend(name: string, fn: IExtendCallback): IExtendFunc;
  32. // check if the string matches the comparison.
  33. equals(str: string, comparison: any): boolean;
  34. // check if the string contains the seed.
  35. contains(str: string, elem: any): boolean;
  36. // check if string matches the pattern.
  37. matches(str: string, pattern: any, modifiers?: string): boolean;
  38. // check if the string is an email.
  39. isEmail(str: string): boolean;
  40. // check if the string is an URL.
  41. isURL(str: string, options?: IURLoptions): boolean;
  42. // check if the string is a fully qualified domain name (e.g. domain.com).
  43. isFQDN(str: string, options?: IFQDNoptions): boolean;
  44. // check if the string is an IP (version 4 or 6).
  45. isIP(str: string, version?: number): boolean;
  46. // check if the string contains only letters (a-zA-Z).
  47. isAlpha(str: string): boolean;
  48. // check if the string contains only numbers.
  49. isNumeric(str: string): boolean;
  50. // check if the string contains only letters and numbers.
  51. isAlphanumeric(str: string): boolean;
  52. // check if a string is base64 encoded.
  53. isBase64(str: string): boolean;
  54. // check if the string is a hexadecimal number.
  55. isHexadecimal(str: string): boolean;
  56. // check if the string is a hexadecimal color.
  57. isHexColor(str: string): boolean;
  58. // check if the string is lowercase.
  59. isLowercase(str: string): boolean;
  60. // check if the string is uppercase.
  61. isUppercase(str: string): boolean;
  62. // check if the string is an integer.
  63. isInt(str: string): boolean;
  64. // check if the string is a float.
  65. isFloat(str: string): boolean;
  66. // check if the string is a number that's divisible by another.
  67. isDivisibleBy(str: string, number: number): boolean;
  68. // check if the string is null.
  69. isNull(str: string): boolean;
  70. // check if the string's length falls in a range. Note: this function takes into account surrogate pairs.
  71. isLength(str: string, min: number, max?: number): boolean;
  72. // check if the string's length (in bytes) falls in a range.
  73. isByteLength(str: string, min: number, max?: number): boolean;
  74. // check if the string is a UUID (version 3, 4 or 5).
  75. isUUID(str: string, version?: number): boolean;
  76. // check if the string is a date.
  77. isDate(str: string): boolean;
  78. // check if the string is a date that's after the specified date (defaults to now).
  79. isAfter(str: string, date?: Date): boolean;
  80. // check if the string is a date that's before the specified date.
  81. isBefore(str: string, date?: Date): boolean;
  82. // check if the string is in a array of allowed values.
  83. isIn(str: string, values: any[]): boolean;
  84. // check if the string is a credit card.
  85. isCreditCard(str: string): boolean;
  86. // check if the string is an ISBN (version 10 or 13).
  87. isISBN(str: string, version?: number): boolean;
  88. // check if the string is valid JSON (note: uses JSON.parse).
  89. isJSON(str: string): boolean;
  90. // check if the string contains one or more multibyte chars.
  91. isMultibyte(str: string): boolean;
  92. // check if the string contains ASCII chars only.
  93. isAscii(str: string): boolean;
  94. // check if the string contains any full-width chars.
  95. isFullWidth(str: string): boolean;
  96. // check if the string contains any half-width chars.
  97. isHalfWidth(str: string): boolean;
  98. // check if the string contains a mixture of full and half-width chars.
  99. isVariableWidth(str: string): boolean;
  100. // check if the string contains any surrogate pairs chars.
  101. isSurrogatePair(str: string): boolean;
  102. // check if the string is a valid hex-encoded representation of a MongoDB ObjectId.
  103. isMongoId(str: string): boolean;
  104. // convert the input to a string.
  105. toString(input: any): string;
  106. // convert the input to a date, or null if the input is not a date.
  107. toDate(input: any): any; // Date or null
  108. // convert the input to a float, or NaN if the input is not a float.
  109. toFloat(input:any): number; // number or NaN
  110. // convert the input to an integer, or NaN if the input is not an integer.
  111. toInt(input:any, radix?: number): number; // number or NaN
  112. // convert the input to a boolean.
  113. toBoolean(input:any, strict?: boolean): boolean;
  114. // trim characters (whitespace by default) from both sides of the input.
  115. trim(input: any, chars?: string): string;
  116. // trim characters from the left-side of the input.
  117. ltrim(input: any, chars?: string): string;
  118. // trim characters from the right-side of the input.
  119. rtrim(input: any, chars?: string): string;
  120. // replace <, >, &, ' and " with HTML entities.
  121. escape(input: string): string;
  122. // remove characters with a numerical value < 32 and 127
  123. stripLow(input: string, keep_new_lines?: boolean): string;
  124. // remove characters that do not appear in the whitelist.
  125. whitelist(input: string, chars: string): string;
  126. // remove characters that appear in the blacklist.
  127. blacklist(input: string, chars: string): string;
  128. // canonicalize an email address.
  129. normalizeEmail(email: string, options?: IEmailoptions): string;
  130. }
  131. declare module "validator" {
  132. var validator: IValidatorStatic;
  133. export = validator;
  134. }