@depup/express-validator 7.3.1-depup.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/changes.json +14 -0
  4. package/lib/base.d.ts +187 -0
  5. package/lib/base.js +8 -0
  6. package/lib/chain/context-handler-impl.d.ts +13 -0
  7. package/lib/chain/context-handler-impl.js +52 -0
  8. package/lib/chain/context-handler.d.ts +110 -0
  9. package/lib/chain/context-handler.js +2 -0
  10. package/lib/chain/context-runner-impl.d.ts +18 -0
  11. package/lib/chain/context-runner-impl.js +72 -0
  12. package/lib/chain/context-runner.d.ts +22 -0
  13. package/lib/chain/context-runner.js +2 -0
  14. package/lib/chain/index.d.ts +9 -0
  15. package/lib/chain/index.js +25 -0
  16. package/lib/chain/sanitizers-impl.d.ts +29 -0
  17. package/lib/chain/sanitizers-impl.js +80 -0
  18. package/lib/chain/sanitizers.d.ts +42 -0
  19. package/lib/chain/sanitizers.js +2 -0
  20. package/lib/chain/validation-chain.d.ts +18 -0
  21. package/lib/chain/validation-chain.js +2 -0
  22. package/lib/chain/validators-impl.d.ts +121 -0
  23. package/lib/chain/validators-impl.js +353 -0
  24. package/lib/chain/validators.d.ts +181 -0
  25. package/lib/chain/validators.js +2 -0
  26. package/lib/context-builder.d.ts +20 -0
  27. package/lib/context-builder.js +52 -0
  28. package/lib/context-items/bail.d.ts +5 -0
  29. package/lib/context-items/bail.js +13 -0
  30. package/lib/context-items/chain-condition.d.ts +9 -0
  31. package/lib/context-items/chain-condition.js +16 -0
  32. package/lib/context-items/context-item.d.ts +5 -0
  33. package/lib/context-items/context-item.js +2 -0
  34. package/lib/context-items/custom-condition.d.ts +8 -0
  35. package/lib/context-items/custom-condition.js +24 -0
  36. package/lib/context-items/custom-validation.d.ts +10 -0
  37. package/lib/context-items/custom-validation.js +34 -0
  38. package/lib/context-items/index.d.ts +5 -0
  39. package/lib/context-items/index.js +21 -0
  40. package/lib/context-items/sanitization.d.ts +12 -0
  41. package/lib/context-items/sanitization.js +34 -0
  42. package/lib/context-items/standard-validation.d.ts +13 -0
  43. package/lib/context-items/standard-validation.js +25 -0
  44. package/lib/context.d.ts +61 -0
  45. package/lib/context.js +117 -0
  46. package/lib/express-validator.d.ts +153 -0
  47. package/lib/express-validator.js +125 -0
  48. package/lib/field-selection.d.ts +22 -0
  49. package/lib/field-selection.js +221 -0
  50. package/lib/index.d.ts +9 -0
  51. package/lib/index.js +25 -0
  52. package/lib/matched-data.d.ts +26 -0
  53. package/lib/matched-data.js +45 -0
  54. package/lib/middlewares/check.d.ts +3 -0
  55. package/lib/middlewares/check.js +23 -0
  56. package/lib/middlewares/exact.d.ts +29 -0
  57. package/lib/middlewares/exact.js +68 -0
  58. package/lib/middlewares/one-of.d.ts +28 -0
  59. package/lib/middlewares/one-of.js +91 -0
  60. package/lib/middlewares/schema.d.ts +108 -0
  61. package/lib/middlewares/schema.js +112 -0
  62. package/lib/middlewares/validation-chain-builders.d.ts +43 -0
  63. package/lib/middlewares/validation-chain-builders.js +49 -0
  64. package/lib/options.d.ts +377 -0
  65. package/lib/options.js +2 -0
  66. package/lib/utils.d.ts +12 -0
  67. package/lib/utils.js +56 -0
  68. package/lib/validation-result.d.ts +67 -0
  69. package/lib/validation-result.js +80 -0
  70. package/package.json +97 -0
@@ -0,0 +1,377 @@
1
+ export type URLProtocol = 'http' | 'https' | 'ftp' | string;
2
+ export type UUIDVersion = 1 | 2 | 3 | 4 | 5 | 7 | '1' | '2' | '3' | '4' | '5' | '7' | 'all' | 'loose';
3
+ export type IPVersion = 4 | 6;
4
+ export type AlphaLocale = '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' | 'az-AZ' | 'bg-BG' | 'bn-BD' | 'cs-CZ' | 'da-DK' | 'de-DE' | 'el-GR' | 'en-AU' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-NZ' | 'en-US' | 'en-ZA' | 'en-ZM' | 'es-ES' | 'eo' | 'fa-AF' | 'fa-IR' | 'fi-FI' | 'fr-FR' | 'gu-IN' | 'he' | 'hi-IN' | 'hu-HU' | 'id-ID' | 'it-IT' | 'ja-JP' | 'kk-KZ' | 'kn-IN' | 'ko-KR' | 'ku-IQ' | 'ml-IN' | 'nb-NO' | 'nl-NL' | 'nn-NO' | 'or-IN' | 'pa-IN' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ru-RU' | 'si-LK' | 'sk-SK' | 'sl-SI' | 'sr-RS' | 'sr-RS@latin' | 'sv-SE' | 'ta-IN' | 'te-IN' | 'th-TH' | 'tr-TR' | 'uk-UA' | 'vi-VN';
5
+ export type AlphanumericLocale = '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' | 'az-AZ' | 'bg-BG' | 'bn-BD' | 'cs-CZ' | 'da-DK' | 'de-DE' | 'el-GR' | 'en-AU' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-NZ' | 'en-US' | 'en-ZA' | 'en-ZM' | 'es-ES' | 'eo' | 'fa-AF' | 'fa-IR' | 'fi-FI' | 'fr-FR' | 'fr-BE' | 'gu-IN' | 'he' | 'hi-IN' | 'hu-HU' | 'it-IT' | 'id-ID' | 'ja-JP' | 'kk-KZ' | 'kn-IN' | 'ko-KR' | 'ku-IQ' | 'ml-IN' | 'nb-NO' | 'nl-BE' | 'nl-NL' | 'nn-NO' | 'or-IN' | 'pa-IN' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ru-RU' | 'si-LK' | 'sk-SK' | 'sl-SI' | 'sr-RS' | 'sr-RS@latin' | 'sv-SE' | 'ta-IN' | 'te-IN' | 'th-TH' | 'tr-TR' | 'uk-UA' | 'vi-VN';
6
+ export type MobilePhoneLocale = 'any' | 'am-AM' | 'ar-AE' | 'ar-BH' | 'ar-DZ' | 'ar-EG' | 'ar-EH' | 'ar-IQ' | 'ar-JO' | 'ar-KW' | 'ar-LB' | 'ar-LY' | 'ar-MA' | 'ar-OM' | 'ar-QA' | 'ar-PS' | 'ar-SA' | 'ar-SD' | 'ar-SY' | 'ar-TN' | 'ar-YE' | 'az-AZ' | 'be-BY' | 'bg-BG' | 'bn-BD' | 'bs-BA' | 'cs-CZ' | 'de-AT' | 'de-CH' | 'de-DE' | 'de-LU' | 'da-DK' | 'dv-MV' | 'dz-BT' | 'el-CY' | 'el-GR' | 'en-AG' | 'en-AI' | 'en-AU' | 'en-BM' | 'en-BS' | 'en-BW' | 'en-CA' | 'en-GB' | 'en-GG' | 'en-GH' | 'en-GY' | 'en-HK' | 'en-HN' | 'en-IE' | 'en-IN' | 'en-JM' | 'en-KE' | 'en-KI' | 'en-KN' | 'en-LS' | 'en-MT' | 'en-MU' | 'en-MW' | 'en-NA' | 'en-NG' | 'en-NZ' | 'en-PG' | 'en-PH' | 'en-PK' | 'en-RW' | 'en-SG' | 'en-SL' | 'en-SS' | 'en-TZ' | 'en-UG' | 'en-US' | 'en-ZA' | 'en-ZM' | 'en-ZW' | 'es-AR' | 'es-BO' | 'es-CL' | 'es-CO' | 'es-CR' | 'es-CU' | 'es-DO' | 'es-EC' | 'es-ES' | 'es-GT' | 'es-HN' | 'es-MX' | 'es-NI' | 'es-PA' | 'es-PE' | 'es-PY' | 'es-SV' | 'es-UY' | 'es-VE' | 'et-EE' | 'fa-AF' | 'fa-IR' | 'fi-FI' | 'fj-FJ' | 'fo-FO' | 'fr-BE' | 'fr-BF' | 'fr-BJ' | 'fr-CD' | 'fr-CF' | 'fr-CH' | 'fr-CM' | 'fr-FR' | 'fr-GF' | 'fr-GP' | 'fr-MQ' | 'fr-PF' | 'fr-RE' | 'fr-WF' | 'ga-IE' | 'he-IL' | 'hu-HU' | 'id-ID' | 'ir-IR' | 'it-CH' | 'it-IT' | 'it-SM' | 'ja-JP' | 'ka-GE' | 'kk-KZ' | 'kl-GL' | 'ko-KR' | 'ky-KG' | 'lt-LT' | 'lv-LV' | 'mg-MG' | 'mk-MK' | 'mn-MN' | 'ms-MY' | 'my-MM' | 'mz-MZ' | 'nb-NO' | 'nl-AW' | 'nl-BE' | 'nl-NL' | 'ne-NP' | 'nn-NO' | 'pl-PL' | 'pt-AO' | 'pt-BR' | 'pt-PT' | 'ro-MD' | 'ro-RO' | 'ru-RU' | 'si-LK' | 'sk-SK' | 'sl-SI' | 'so-SO' | 'sq-AL' | 'sr-RS' | 'sv-SE' | 'tg-TJ' | 'th-TH' | 'tk-TM' | 'tr-TR' | 'uk-UA' | 'uz-Uz' | 'vi-VN' | 'zh-CN' | 'zh-HK' | 'zh-TW';
7
+ export type PostalCodeLocale = 'any' | 'AD' | 'AT' | 'AU' | 'AZ' | 'BA' | 'BD' | 'BE' | 'BG' | 'BR' | 'BY' | 'CA' | 'CH' | 'CN' | 'CO' | 'CZ' | 'DE' | 'DK' | 'DO' | 'DZ' | 'EE' | 'ES' | 'FI' | 'FR' | 'GB' | 'GR' | 'HR' | 'HT' | 'HU' | 'ID' | 'IL' | 'IN' | 'IR' | 'IS' | 'IT' | 'JP' | 'KE' | 'KR' | 'LI' | 'LK' | 'LT' | 'LU' | 'LV' | 'MT' | 'MX' | 'MY' | 'NL' | 'NO' | 'NP' | 'NZ' | 'PK' | 'PL' | 'PR' | 'PT' | 'RO' | 'RU' | 'SA' | 'SE' | 'SG' | 'SI' | 'SK' | 'TH' | 'TN' | 'TW' | 'UA' | 'US' | 'ZA' | 'ZM';
8
+ export type HashAlgorithm = 'md4' | 'md5' | 'sha1' | 'sha256' | 'sha384' | 'sha512' | 'ripemd128' | 'ripemd160' | 'tiger128' | 'tiger160' | 'tiger192' | 'crc32' | 'crc32b';
9
+ export type IBANCode = 'AD' | 'AE' | 'AL' | 'AT' | 'AZ' | 'BA' | 'BE' | 'BG' | 'BH' | 'BR' | 'BY' | 'CH' | 'CR' | 'CY' | 'CZ' | 'DE' | 'DK' | 'DO' | 'DZ' | 'EE' | 'EG' | 'ES' | 'FI' | 'FO' | 'FR' | 'GB' | 'GE' | 'GI' | 'GL' | 'GR' | 'GT' | 'HR' | 'HU' | 'IE' | 'IL' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JO' | 'KW' | 'KZ' | 'LB' | 'LC' | 'LI' | 'LT' | 'LU' | 'LV' | 'MC' | 'MD' | 'ME' | 'MK' | 'MR' | 'MT' | 'MU' | 'MZ' | 'NL' | 'NO' | 'PK' | 'PL' | 'PS' | 'PT' | 'QA' | 'RO' | 'RS' | 'SA' | 'SC' | 'SE' | 'SI' | 'SK' | 'SM' | 'SV' | 'TL' | 'TN' | 'TR' | 'UA' | 'VA' | 'VG' | 'XK';
10
+ export interface IsIBANOptions {
11
+ whitelist?: readonly IBANCode[];
12
+ blacklist?: readonly IBANCode[];
13
+ }
14
+ export type IdentityCardLocale = 'any' | 'ar-LY' | 'ar-TN' | 'ES' | 'FI' | 'he-IL' | 'hk-HK' | 'IN' | 'IT' | 'IR' | 'MZ' | 'NO' | 'PK' | 'PL' | 'TH' | 'zh-CN' | 'zh-TW';
15
+ export type PassportCountryCode = 'AM' | 'AR' | 'AT' | 'AU' | 'AZ' | 'BE' | 'BG' | 'BY' | 'BR' | 'CA' | 'CH' | 'CN' | 'CY' | 'CZ' | 'DE' | 'DK' | 'DZ' | 'EE' | 'ES' | 'FI' | 'FR' | 'GB' | 'GR' | 'HR' | 'HU' | 'ID' | 'IE' | 'IN' | 'IR' | 'IS' | 'IT' | 'JM' | 'JP' | 'KR' | 'KZ' | 'LI' | 'LT' | 'LU' | 'LV' | 'LY' | 'MT' | 'MY' | 'MZ' | 'NL' | 'NZ' | 'PH' | 'PK' | 'PL' | 'PO' | 'PT' | 'RO' | 'RU' | 'SE' | 'SL' | 'SK' | 'TH' | 'TR' | 'UA' | 'US' | 'ZA';
16
+ export type IsLicensePlateLocale = 'cs-CZ' | 'de-DE' | 'de-LI' | 'en-NI' | 'en-PK' | 'en-SG' | 'es-AR' | 'fi-FI' | 'hu-HU' | 'pt-BR' | 'pt-PT' | 'sq-AL' | 'sv-SE' | 'any';
17
+ export type TaxIDLocale = 'bg-BG' | 'cs-CZ' | 'de-AT' | 'de-DE' | 'dk-DK' | 'el-CY' | 'el-GR' | 'en-CA' | 'en-GB' | 'en-IE' | 'en-US' | 'es-AR' | 'es-ES' | 'et-EE' | 'fi-FI' | 'fr-BE' | 'fr-FR' | 'fr-LU' | 'hr-HR' | 'hu-HU' | 'it-IT' | 'lb-LU' | 'lt-LT' | 'lv-LV' | 'mt-MT' | 'nl-BE' | 'nl-NL' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ro-RO' | 'sk-SK' | 'sl-SI' | 'sv-SE' | 'uk-UA';
18
+ export type VATCountryCode = 'GB' | 'IT' | 'NL' | 'AT' | 'BE' | 'BG' | 'HR' | 'CU' | 'CY' | 'CZ' | 'DK' | 'EE' | 'FI' | 'FR' | 'DE' | 'EL' | 'HU' | 'IE' | 'LV' | 'LT' | 'LU' | 'MT' | 'PL' | 'PT' | 'RO' | 'SK' | 'SI' | 'ES' | 'SE' | 'AL' | 'MK' | 'AU' | 'BY' | 'CA' | 'IS' | 'IN' | 'ID' | 'IL' | 'KZ' | 'NZ' | 'NG' | 'NO' | 'PH' | 'RU' | 'SM' | 'SA' | 'RS' | 'CH' | 'TR' | 'UA' | 'UZ' | 'AR' | 'BO' | 'BR' | 'CL' | 'CO' | 'CR' | 'EC' | 'SV' | 'GT' | 'HN' | 'MX' | 'NI' | 'PA' | 'PY' | 'PE' | 'DO' | 'UY' | 'VE';
19
+ export interface MinMaxOptions {
20
+ min?: number;
21
+ max?: number;
22
+ }
23
+ export interface MinMaxExtendedOptions extends MinMaxOptions {
24
+ lt?: number;
25
+ gt?: number;
26
+ }
27
+ /**
28
+ * defaults to
29
+ * {
30
+ * ignoreCase: false|
31
+ * minOccurrences: 1
32
+ * }
33
+ */
34
+ export interface ContainsOptions {
35
+ ignoreCase?: boolean;
36
+ minOccurrences?: number;
37
+ }
38
+ /**
39
+ * defaults to
40
+ * {
41
+ * comparisonDate: Date().toString()
42
+ * }
43
+ */
44
+ export interface IsAfterOptions {
45
+ comparisonDate?: string;
46
+ }
47
+ export interface IsAlphaOptions {
48
+ ignore?: string | string[] | RegExp;
49
+ }
50
+ export interface IsAlphanumericOptions {
51
+ ignore?: string | RegExp;
52
+ }
53
+ /**
54
+ * defaults to
55
+ * {
56
+ * crockford: false
57
+ * }
58
+ */
59
+ export interface IsBase32Options {
60
+ crockford?: boolean;
61
+ }
62
+ /**
63
+ * defaults to
64
+ * {
65
+ * urlSafe: false
66
+ * }
67
+ */
68
+ export interface IsBase64Options {
69
+ urlSafe?: boolean;
70
+ }
71
+ /**
72
+ * defaults to
73
+ * {
74
+ * comparisonDate: new Date().toString()
75
+ * }
76
+ */
77
+ export interface IsBeforeOptions {
78
+ comparisonDate?: string;
79
+ }
80
+ /**
81
+ * defaults to
82
+ * {
83
+ * strict: false
84
+ * loose: false
85
+ * }
86
+ */
87
+ export interface IsBooleanOptions {
88
+ strict?: boolean;
89
+ loose?: boolean;
90
+ }
91
+ /**
92
+ * defaults to
93
+ * {
94
+ * includePercentValues: true
95
+ * allowSpaces: true
96
+ * }
97
+ */
98
+ export interface IsRgbColorOptions {
99
+ includePercentValues?: boolean;
100
+ allowSpaces?: boolean;
101
+ }
102
+ export interface IsCreditCard {
103
+ provider?: 'amex' | 'dinersclub' | 'discover' | 'jcb' | 'mastercard' | 'unionpay' | 'visa';
104
+ }
105
+ /**
106
+ * defaults to
107
+ * {
108
+ * symbol: '$'|
109
+ * require_symbol: false|
110
+ * allow_space_after_symbol: false|
111
+ * symbol_after_digits: false|
112
+ * allow_negatives: true|
113
+ * parens_for_negatives: false|
114
+ * negative_sign_before_digits: false|
115
+ * negative_sign_after_digits: false|
116
+ * allow_negative_sign_placeholder: false|
117
+ * thousands_separator: '|'|
118
+ * decimal_separator: '.'|
119
+ * allow_space_after_digits: false
120
+ * }
121
+ */
122
+ export interface IsCurrencyOptions {
123
+ symbol?: string;
124
+ require_symbol?: boolean;
125
+ allow_space_after_symbol?: boolean;
126
+ symbol_after_digits?: boolean;
127
+ allow_negatives?: boolean;
128
+ parens_for_negatives?: boolean;
129
+ negative_sign_before_digits?: boolean;
130
+ negative_sign_after_digits?: boolean;
131
+ allow_negative_sign_placeholder?: boolean;
132
+ thousands_separator?: string;
133
+ decimal_separator?: string;
134
+ allow_decimal?: boolean;
135
+ require_decimal?: boolean;
136
+ digits_after_decimal?: number[];
137
+ allow_space_after_digits?: boolean;
138
+ }
139
+ /**
140
+ * defaults to
141
+ * {
142
+ * format: 'YYYY/MM/DD'|
143
+ * delimiters: ['/'| '-']|
144
+ * strictMode: false
145
+ * }
146
+ */
147
+ export interface IsDateOptions {
148
+ format?: string;
149
+ delimiters?: string[];
150
+ strictMode?: boolean;
151
+ }
152
+ export interface IsDecimalOptions {
153
+ decimal_digits?: string;
154
+ force_decimal?: boolean;
155
+ locale?: AlphanumericLocale;
156
+ blacklisted_chars?: string;
157
+ }
158
+ export interface IsEmailOptions {
159
+ allow_display_name?: boolean;
160
+ allow_underscores?: boolean;
161
+ allow_utf8_local_part?: boolean;
162
+ require_tld?: boolean;
163
+ ignore_max_length?: boolean;
164
+ allow_ip_domain?: boolean;
165
+ domain_specific_validation?: boolean;
166
+ blacklisted_chars?: string;
167
+ host_blacklist?: (string | RegExp)[];
168
+ host_whitelist?: (string | RegExp)[];
169
+ }
170
+ /**
171
+ * defaults to
172
+ * {
173
+ * ignore_whitespace: false
174
+ * }
175
+ */
176
+ export interface IsEmptyOptions {
177
+ ignore_whitespace: boolean;
178
+ }
179
+ export interface IsFloatOptions extends MinMaxExtendedOptions {
180
+ locale?: AlphanumericLocale;
181
+ }
182
+ /**
183
+ * defaults to
184
+ * {
185
+ * require_tld: true|
186
+ * allow_underscores: false|
187
+ * allow_trailing_dot: false|
188
+ * allow_numeric_tld: false|
189
+ * allow_wildcard: false|
190
+ * ignore_max_length: false
191
+ * }
192
+ */
193
+ export interface IsFQDNOptions {
194
+ require_tld?: boolean;
195
+ allow_underscores?: boolean;
196
+ allow_trailing_dot?: boolean;
197
+ allow_numeric_tld?: boolean;
198
+ allow_wildcard?: boolean;
199
+ ignore_max_length?: boolean;
200
+ }
201
+ export interface IsIntOptions extends MinMaxExtendedOptions {
202
+ allow_leading_zeroes?: boolean;
203
+ }
204
+ /**
205
+ * defaults to
206
+ * {
207
+ * allow_primitives: false
208
+ * }
209
+ */
210
+ export interface IsJSONOptions {
211
+ allow_primitives?: boolean;
212
+ }
213
+ /**
214
+ * defaults to
215
+ * {
216
+ * checkDMS: false
217
+ * }
218
+ */
219
+ export interface IsLatLongOptions {
220
+ checkDMS?: boolean;
221
+ }
222
+ export interface IsLengthOptions extends MinMaxOptions {
223
+ discreteLengths?: number[];
224
+ }
225
+ /**
226
+ * defaults to
227
+ * {
228
+ * allow_hyphens: false
229
+ * }
230
+ */
231
+ export interface IsIMEIOptions {
232
+ allow_hyphens?: boolean;
233
+ }
234
+ /**
235
+ * defaults to
236
+ * {
237
+ * strict: false|
238
+ * strictSeparator: false
239
+ * }
240
+ */
241
+ export interface IsISO8601Options {
242
+ strict?: boolean;
243
+ strictSeparator?: boolean;
244
+ }
245
+ export interface IsISBNOptions {
246
+ version?: '10' | '13';
247
+ }
248
+ /**
249
+ * defaults to
250
+ * {
251
+ * case_sensitive: false|
252
+ * require_hyphen: false
253
+ * }
254
+ */
255
+ export interface IsISSNOptions {
256
+ case_sensitive?: boolean;
257
+ require_hyphen?: boolean;
258
+ }
259
+ /**
260
+ * defaults to
261
+ * ```js
262
+ * {
263
+ * no_separators: false
264
+ * }
265
+ * ```
266
+ */
267
+ export interface IsMACAddressOptions {
268
+ no_separators?: boolean;
269
+ /**
270
+ * @deprecated use `no_separators` instead
271
+ */
272
+ no_colons?: boolean;
273
+ eui?: '48' | '64';
274
+ }
275
+ export interface IsMobilePhoneOptions {
276
+ strictMode?: boolean;
277
+ }
278
+ /**
279
+ * defaults to
280
+ * {
281
+ * no_symbols: false
282
+ * }
283
+ */
284
+ export interface IsNumericOptions {
285
+ no_symbols: boolean;
286
+ locale?: AlphanumericLocale;
287
+ }
288
+ /**
289
+ * defaults to
290
+ * {
291
+ * minLength: 8|
292
+ * minLowercase: 1|
293
+ * minUppercase: 1|
294
+ * minNumbers: 1|
295
+ * minSymbols: 1|
296
+ * returnScore: false|
297
+ * pointsPerUnique: 1|
298
+ * pointsPerRepeat: 0.5|
299
+ * pointsForContainingLower: 10|
300
+ * pointsForContainingUpper: 10|
301
+ * pointsForContainingNumber: 10|
302
+ * pointsForContainingSymbol: 10
303
+ * }
304
+ */
305
+ export interface IsStrongPasswordOptions {
306
+ minLength?: number;
307
+ minLowercase?: number;
308
+ minUppercase?: number;
309
+ minNumbers?: number;
310
+ minSymbols?: number;
311
+ returnScore?: boolean;
312
+ pointsPerUnique?: number;
313
+ pointsPerRepeat?: number;
314
+ pointsForContainingLower?: number;
315
+ pointsForContainingUpper?: number;
316
+ pointsForContainingNumber?: number;
317
+ pointsForContainingSymbol?: number;
318
+ }
319
+ /**
320
+ * defaults to
321
+ * {
322
+ * protocols: ['http'|'https'|'ftp']|
323
+ * require_tld: true|
324
+ * require_protocol: false|
325
+ * require_host: true|
326
+ * require_port: false;
327
+ * require_valid_protocol: true|
328
+ * allow_underscores: false|
329
+ * host_whitelist: false|
330
+ * host_blacklist: false|
331
+ * allow_trailing_dot: false|
332
+ * allow_protocol_relative_urls: false|
333
+ * validate_length: true|
334
+ * allow_fragments: true|
335
+ * allow_query_components: true
336
+ * }
337
+ */
338
+ export interface IsURLOptions extends IsFQDNOptions {
339
+ protocols?: URLProtocol[];
340
+ require_protocol?: boolean;
341
+ require_host?: boolean;
342
+ require_port?: boolean;
343
+ require_valid_protocol?: boolean;
344
+ host_whitelist?: (string | RegExp)[];
345
+ host_blacklist?: (string | RegExp)[];
346
+ allow_protocol_relative_urls?: boolean;
347
+ disallow_auth?: boolean;
348
+ validate_length?: boolean;
349
+ max_allowed_length?: number;
350
+ allow_fragments?: boolean;
351
+ allow_query_components?: boolean;
352
+ }
353
+ /**
354
+ * defaults to
355
+ * {
356
+ * hourFormat: 'hour24'|
357
+ * mode: 'default'|
358
+ * };
359
+ */
360
+ export interface IsTimeOptions {
361
+ hourFormat?: 'hour24' | 'hour12';
362
+ mode?: 'default' | 'withSeconds';
363
+ }
364
+ export interface NormalizeEmailOptions {
365
+ all_lowercase?: boolean;
366
+ gmail_lowercase?: boolean;
367
+ gmail_remove_dots?: boolean;
368
+ gmail_remove_subaddress?: boolean;
369
+ gmail_convert_googlemaildotcom?: boolean;
370
+ outlookdotcom_lowercase?: boolean;
371
+ outlookdotcom_remove_subaddress?: boolean;
372
+ yahoo_lowercase?: boolean;
373
+ yahoo_remove_subaddress?: boolean;
374
+ icloud_lowercase?: boolean;
375
+ icloud_remove_subaddress?: boolean;
376
+ yandex_convert_yandexru?: boolean;
377
+ }
package/lib/options.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/utils.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { Request } from './base';
2
+ import { ContextRunningOptions, ResultWithContext, ValidationChainLike } from './chain';
3
+ export declare const bindAll: <T>(object: T) => { [K in keyof T]: T[K]; };
4
+ export declare function toString(value: any): string;
5
+ /**
6
+ * Runs all validation chains, and returns their results.
7
+ *
8
+ * If one of them has a request-level bail set, the previous chains will be awaited on so that
9
+ * results are not skewed, which can be slow.
10
+ * If this same chain also contains errors, no further chains are run.
11
+ */
12
+ export declare function runAllChains(req: Request, chains: readonly ValidationChainLike[], runOpts?: ContextRunningOptions): Promise<ResultWithContext[]>;
package/lib/utils.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindAll = void 0;
4
+ exports.toString = toString;
5
+ exports.runAllChains = runAllChains;
6
+ const bindAll = (object) => {
7
+ const protoKeys = Object.getOwnPropertyNames(Object.getPrototypeOf(object));
8
+ protoKeys.forEach(key => {
9
+ const maybeFn = object[key];
10
+ if (typeof maybeFn === 'function' && key !== 'constructor') {
11
+ object[key] = maybeFn.bind(object);
12
+ }
13
+ });
14
+ return object;
15
+ };
16
+ exports.bindAll = bindAll;
17
+ function toString(value) {
18
+ if (value instanceof Date) {
19
+ return value.toISOString();
20
+ }
21
+ else if (value && typeof value === 'object' && value.toString) {
22
+ if (typeof value.toString !== 'function') {
23
+ return Object.getPrototypeOf(value).toString.call(value);
24
+ }
25
+ return value.toString();
26
+ }
27
+ else if (value == null || (isNaN(value) && !value.length)) {
28
+ return '';
29
+ }
30
+ return String(value);
31
+ }
32
+ /**
33
+ * Runs all validation chains, and returns their results.
34
+ *
35
+ * If one of them has a request-level bail set, the previous chains will be awaited on so that
36
+ * results are not skewed, which can be slow.
37
+ * If this same chain also contains errors, no further chains are run.
38
+ */
39
+ async function runAllChains(req, chains, runOpts) {
40
+ const promises = [];
41
+ for (const chain of chains) {
42
+ const bails = chain.builder.build().bail;
43
+ if (bails) {
44
+ await Promise.all(promises);
45
+ }
46
+ const resultPromise = chain.run(req, runOpts);
47
+ promises.push(resultPromise);
48
+ if (bails) {
49
+ const result = await resultPromise;
50
+ if (!result.isEmpty()) {
51
+ break;
52
+ }
53
+ }
54
+ }
55
+ return Promise.all(promises);
56
+ }
@@ -0,0 +1,67 @@
1
+ import { Request, ValidationError } from './base';
2
+ /**
3
+ * Given a validation error, returns a new value that represents it.
4
+ */
5
+ export type ErrorFormatter<T = any> = (error: ValidationError) => T;
6
+ type ToArrayOptions = {
7
+ /**
8
+ * Whether only the first error of each field should be returned.
9
+ * @default false
10
+ */
11
+ onlyFirstError?: boolean;
12
+ };
13
+ export type ResultFactory<T> = (req: Request) => Result<T>;
14
+ interface ResultFactoryBuilderOptions<T = any> {
15
+ /**
16
+ * The default error formatter of every {@link Result} instance returned by
17
+ * the custom `validationResult()` function.
18
+ */
19
+ formatter: ErrorFormatter<T>;
20
+ }
21
+ /**
22
+ * Extracts the validation errors of an express request
23
+ */
24
+ export declare const validationResult: ResultFactory<ValidationError> & {
25
+ withDefaults: typeof withDefaults;
26
+ };
27
+ /**
28
+ * The current state of the validation errors in a request.
29
+ */
30
+ export declare class Result<T = any> {
31
+ private formatter;
32
+ private readonly errors;
33
+ constructor(formatter: ErrorFormatter<T>, errors: readonly ValidationError[]);
34
+ /**
35
+ * Gets the validation errors as an array.
36
+ *
37
+ * @param options.onlyFirstError whether only the first error of each
38
+ */
39
+ array(options?: ToArrayOptions): T[];
40
+ /**
41
+ * Gets the validation errors as an object.
42
+ * If a field has more than one error, only the first one is set in the resulting object.
43
+ *
44
+ * @returns an object from field name to error
45
+ */
46
+ mapped(): Record<string, T>;
47
+ /**
48
+ * Specifies a function to format errors with.
49
+ * @param formatter the function to use for formatting errors
50
+ * @returns A new {@link Result} instance with the given formatter
51
+ */
52
+ formatWith<T2>(formatter: ErrorFormatter<T2>): Result<T2>;
53
+ /**
54
+ * @returns `true` if there are no errors, `false` otherwise
55
+ */
56
+ isEmpty(): boolean;
57
+ /**
58
+ * Throws an error if there are validation errors.
59
+ */
60
+ throw(): void;
61
+ }
62
+ /**
63
+ * Creates a `validationResult`-like function with default options passed to every {@link Result} it
64
+ * returns.
65
+ */
66
+ declare function withDefaults<T = any>(options?: Partial<ResultFactoryBuilderOptions<T>>): ResultFactory<T>;
67
+ export {};
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Result = exports.validationResult = void 0;
4
+ const _ = require("lodash");
5
+ const base_1 = require("./base");
6
+ const utils_1 = require("./utils");
7
+ /**
8
+ * Extracts the validation errors of an express request
9
+ */
10
+ exports.validationResult = Object.assign(withDefaults(), { withDefaults });
11
+ /**
12
+ * The current state of the validation errors in a request.
13
+ */
14
+ class Result {
15
+ constructor(formatter, errors) {
16
+ this.formatter = formatter;
17
+ this.errors = errors;
18
+ }
19
+ /**
20
+ * Gets the validation errors as an array.
21
+ *
22
+ * @param options.onlyFirstError whether only the first error of each
23
+ */
24
+ array(options) {
25
+ return options?.onlyFirstError ? Object.values(this.mapped()) : this.errors.map(this.formatter);
26
+ }
27
+ /**
28
+ * Gets the validation errors as an object.
29
+ * If a field has more than one error, only the first one is set in the resulting object.
30
+ *
31
+ * @returns an object from field name to error
32
+ */
33
+ mapped() {
34
+ return this.errors.reduce((mapping, error) => {
35
+ const key = error.type === 'field' ? error.path : `_${error.type}`;
36
+ if (!mapping[key]) {
37
+ mapping[key] = this.formatter(error);
38
+ }
39
+ return mapping;
40
+ }, {});
41
+ }
42
+ /**
43
+ * Specifies a function to format errors with.
44
+ * @param formatter the function to use for formatting errors
45
+ * @returns A new {@link Result} instance with the given formatter
46
+ */
47
+ formatWith(formatter) {
48
+ return new Result(formatter, this.errors);
49
+ }
50
+ /**
51
+ * @returns `true` if there are no errors, `false` otherwise
52
+ */
53
+ isEmpty() {
54
+ return this.errors.length === 0;
55
+ }
56
+ /**
57
+ * Throws an error if there are validation errors.
58
+ */
59
+ throw() {
60
+ if (!this.isEmpty()) {
61
+ throw Object.assign(new Error(), (0, utils_1.bindAll)(this));
62
+ }
63
+ }
64
+ }
65
+ exports.Result = Result;
66
+ /**
67
+ * Creates a `validationResult`-like function with default options passed to every {@link Result} it
68
+ * returns.
69
+ */
70
+ function withDefaults(options = {}) {
71
+ const defaults = {
72
+ formatter: error => error,
73
+ };
74
+ const actualOptions = _.defaults(options, defaults);
75
+ return (req) => {
76
+ const contexts = req[base_1.contextsKey] || [];
77
+ const errors = _.flatMap(contexts, 'errors');
78
+ return new Result(actualOptions.formatter, errors);
79
+ };
80
+ }