|
| 1 | +import type { Assert as BaseAssert } from 'validator.js'; |
| 2 | + |
| 3 | +/** |
| 4 | + * The instance‐side of an Assert (no static factory methods). |
| 5 | + * All core “is.X()” methods and custom asserts produce this. |
| 6 | + */ |
| 7 | +interface AssertInstance { |
| 8 | + /** Returns `true` if the value passes, otherwise returns a Violation/object. */ |
| 9 | + check(value: unknown, group?: string | string[], context?: unknown): true | any; |
| 10 | + /** Throws on failure; returns `true` if the value passes. */ |
| 11 | + validate(value: unknown, group?: string | string[], context?: unknown): true; |
| 12 | + /** Does this assert apply to the given validation group(s)? */ |
| 13 | + requiresValidation(group?: string | string[]): boolean; |
| 14 | + /** Is this assert assigned to the given group? */ |
| 15 | + hasGroup(group: string | string[]): boolean; |
| 16 | + /** Is this assert in any of the provided groups? */ |
| 17 | + hasOneOf(groups: string[]): boolean; |
| 18 | + /** Does this assert belong to at least one group? */ |
| 19 | + hasGroups(): boolean; |
| 20 | +} |
| 21 | + |
| 22 | +export interface ValidatorJSAsserts { |
| 23 | + /** |
| 24 | + * Value is a valid American Bankers Association Routing Number used in ACH payments. |
| 25 | + * @requires abavalidator |
| 26 | + */ |
| 27 | + abaRoutingNumber(): AssertInstance; |
| 28 | + /** Value is a valid Bank Identifier Code (BIC) used for international wire transfers. */ |
| 29 | + bankIdentifierCode(): AssertInstance; |
| 30 | + /** |
| 31 | + * Value is a BigNumber. |
| 32 | + * @requires bignumber.js |
| 33 | + */ |
| 34 | + bigNumber(options?: { validateSignificantDigits?: boolean }): AssertInstance; |
| 35 | + /** |
| 36 | + * Value is a BigNumber equal to a specific value. |
| 37 | + * @requires bignumber.js |
| 38 | + */ |
| 39 | + bigNumberEqualTo(value: string | number, options?: { validateSignificantDigits?: boolean }): AssertInstance; |
| 40 | + /** |
| 41 | + * Value is a BigNumber greater than a specific value. |
| 42 | + * @requires bignumber.js |
| 43 | + */ |
| 44 | + bigNumberGreaterThan(threshold: string | number, options?: { validateSignificantDigits?: boolean }): AssertInstance; |
| 45 | + /** |
| 46 | + * Value is a BigNumber greater than or equal to a specific value. |
| 47 | + * @requires bignumber.js |
| 48 | + */ |
| 49 | + bigNumberGreaterThanOrEqualTo( |
| 50 | + threshold: string | number, |
| 51 | + options?: { validateSignificantDigits?: boolean } |
| 52 | + ): AssertInstance; |
| 53 | + /** |
| 54 | + * Value is a BigNumber less than a specific value. |
| 55 | + * @requires bignumber.js |
| 56 | + */ |
| 57 | + bigNumberLessThan(threshold: string | number, options?: { validateSignificantDigits?: boolean }): AssertInstance; |
| 58 | + /** |
| 59 | + * Value is a BigNumber less than or equal to a specific value. |
| 60 | + * @requires bignumber.js |
| 61 | + */ |
| 62 | + bigNumberLessThanOrEqualTo( |
| 63 | + threshold: string | number, |
| 64 | + options?: { validateSignificantDigits?: boolean } |
| 65 | + ): AssertInstance; |
| 66 | + /** Value is a boolean. */ |
| 67 | + boolean(): AssertInstance; |
| 68 | + /** Valid Canadian zip code. */ |
| 69 | + caZipCode(): AssertInstance; |
| 70 | + /** Run a custom callback function, passing a custom class name. */ |
| 71 | + callback(fn: (value: unknown) => boolean, customClass: string): AssertInstance; |
| 72 | + /** |
| 73 | + * Valid Brazilian CPF number. |
| 74 | + * @requires cpf |
| 75 | + */ |
| 76 | + cpfNumber(): AssertInstance; |
| 77 | + /** |
| 78 | + * Valid credit card number. |
| 79 | + * @requires creditcard |
| 80 | + */ |
| 81 | + creditCard(): AssertInstance; |
| 82 | + /** |
| 83 | + * Valid Mexican CURP number. |
| 84 | + * @requires curp |
| 85 | + */ |
| 86 | + curpNumber(): AssertInstance; |
| 87 | + /** |
| 88 | + * Valid `moment` date, optionally with a specific format. |
| 89 | + * - If `moment` is not available, returns `true` by default. |
| 90 | + * @requires moment |
| 91 | + */ |
| 92 | + date(options?: { format?: string }): AssertInstance; |
| 93 | + /** |
| 94 | + * Valid `moment` date difference greater than a threshold. |
| 95 | + * @requires moment |
| 96 | + */ |
| 97 | + dateDiffGreaterThan( |
| 98 | + threshold: number, |
| 99 | + options?: { |
| 100 | + absolute?: boolean; |
| 101 | + asFloat?: boolean; |
| 102 | + fromDate?: Date | string | null; |
| 103 | + unit?: string; |
| 104 | + } |
| 105 | + ): AssertInstance; |
| 106 | + /** |
| 107 | + * Valid `moment` date difference greater than or equal to a threshold. |
| 108 | + * @requires moment |
| 109 | + */ |
| 110 | + dateDiffGreaterThanOrEqualTo( |
| 111 | + threshold: number, |
| 112 | + options?: { |
| 113 | + absolute?: boolean; |
| 114 | + asFloat?: boolean; |
| 115 | + fromDate?: Date | string | null; |
| 116 | + unit?: string; |
| 117 | + } |
| 118 | + ): AssertInstance; |
| 119 | + /** |
| 120 | + * Valid `moment` date difference less than a threshold. |
| 121 | + * @requires moment |
| 122 | + */ |
| 123 | + dateDiffLessThan( |
| 124 | + threshold: number, |
| 125 | + options?: { |
| 126 | + absolute?: boolean; |
| 127 | + asFloat?: boolean; |
| 128 | + fromDate?: Date | string | null; |
| 129 | + unit?: string; |
| 130 | + } |
| 131 | + ): AssertInstance; |
| 132 | + /** |
| 133 | + * Valid `moment` date difference less than or equal to a threshold. |
| 134 | + * @requires moment |
| 135 | + */ |
| 136 | + dateDiffLessThanOrEqualTo( |
| 137 | + threshold: number, |
| 138 | + options?: { |
| 139 | + absolute?: boolean; |
| 140 | + asFloat?: boolean; |
| 141 | + fromDate?: Date | string | null; |
| 142 | + unit?: string; |
| 143 | + } |
| 144 | + ): AssertInstance; |
| 145 | + /** |
| 146 | + * Extends base email address assert. |
| 147 | + * - Max length is 254 characters. |
| 148 | + * - Returns `true` if email ends in `.deleted`. |
| 149 | + * @requires validator |
| 150 | + */ |
| 151 | + email(): AssertInstance; |
| 152 | + /** Value is an object with exactly the specified keys. */ |
| 153 | + equalKeys(...keys: string[] | [string[]]): AssertInstance; |
| 154 | + /** Validate a hash string using a specific algorithm. */ |
| 155 | + hash(algorithm: 'sha1' | 'sha256' | 'sha512'): AssertInstance; |
| 156 | + /** Valid integer number. */ |
| 157 | + integer(): AssertInstance; |
| 158 | + /** |
| 159 | + * Valid International Bank Account Number (IBAN). |
| 160 | + * @requires iban |
| 161 | + */ |
| 162 | + internationalBankAccountNumber(): AssertInstance; |
| 163 | + /** Value is an IP address. */ |
| 164 | + ip(): AssertInstance; |
| 165 | + /** |
| 166 | + * Value is an ISO 3166 country code. |
| 167 | + * @requires isoc |
| 168 | + */ |
| 169 | + iso3166Country(): AssertInstance; |
| 170 | + /** Value is a JSON string. */ |
| 171 | + json(): AssertInstance; |
| 172 | + /** Value is not empty. */ |
| 173 | + notEmpty(): AssertInstance; |
| 174 | + /** Value is null or passes the provided assert. */ |
| 175 | + nullOr(assert: AssertInstance): AssertInstance; |
| 176 | + /** Value is null or a boolean. */ |
| 177 | + nullOrBoolean(): AssertInstance; |
| 178 | + /** Value is null or a date. */ |
| 179 | + nullOrDate(): AssertInstance; |
| 180 | + /** Value is null or a string. */ |
| 181 | + nullOrString(boundaries?: { min?: number; max?: number }): AssertInstance; |
| 182 | + /** |
| 183 | + * Valid phone number, optionally validating against a specific country code. |
| 184 | + * @requires google-libphonenumber |
| 185 | + */ |
| 186 | + phone(options?: { countryCode?: string }): AssertInstance; |
| 187 | + /** Value is a plain object. */ |
| 188 | + plainObject(): AssertInstance; |
| 189 | + /** |
| 190 | + * Valid Mexican RFC number. |
| 191 | + * @requires validate-rfc |
| 192 | + */ |
| 193 | + rfcNumber(): AssertInstance; |
| 194 | + /** |
| 195 | + * Valid taxpayer identification number (TIN). |
| 196 | + * @requires tin-validator |
| 197 | + */ |
| 198 | + taxpayerIdentificationNumber(): AssertInstance; |
| 199 | + /** |
| 200 | + * Value is UK bank account details using modulus checking. |
| 201 | + * @requires uk-modulus-checking |
| 202 | + */ |
| 203 | + ukModulusChecking(): AssertInstance; |
| 204 | + /** |
| 205 | + * Valid URI. |
| 206 | + * @requires uri-js |
| 207 | + */ |
| 208 | + uri(constraints?: Record<string, any>): AssertInstance; |
| 209 | + /** Value is a US subdivision code. */ |
| 210 | + usSubdivision(options?: { categories?: string[]; alpha2Only?: boolean }): AssertInstance; |
| 211 | + /** Value is a US zip code. */ |
| 212 | + usZipCode(): AssertInstance; |
| 213 | + /** Valid UUID. Accepts version 3, 4, or 5. */ |
| 214 | + uuid(version?: 3 | 4 | 5): AssertInstance; |
| 215 | +} |
0 commit comments