|
1 | 1 | import type { alphanumeric } from './lib/isAlphanumeric' |
| 2 | +import type isDecimal from './lib/isDecimal' |
| 3 | +import type isEmail from './lib/isEmail' |
| 4 | +import type isURL from './lib/isURL' |
2 | 5 | import type { ArrayValidator } from './validators/arrays' |
3 | 6 | import type { BooleanValidator } from './validators/booleans' |
4 | 7 | import type { CustomValidator } from './validators/custom' |
@@ -253,6 +256,86 @@ export interface ValidationConfig { |
253 | 256 | errorMessages?: Record<string, string> |
254 | 257 | } |
255 | 258 |
|
| 259 | +export interface LengthValidator<T> { |
| 260 | + min: (length: number) => T |
| 261 | + max: (length: number) => T |
| 262 | + length: (length: number) => T |
| 263 | +} |
| 264 | + |
| 265 | +export interface StringValidatorType extends Validator<string>, LengthValidator<StringValidator> { |
| 266 | + email: (options?: Parameters<typeof isEmail>[1]) => StringValidator |
| 267 | + url: (options?: Parameters<typeof isURL>[1]) => StringValidator |
| 268 | + matches: (pattern: RegExp) => StringValidator |
| 269 | + equals: (param: string) => StringValidator |
| 270 | + alphanumeric: () => StringValidator |
| 271 | + alpha: () => StringValidator |
| 272 | + numeric: () => StringValidator |
| 273 | + custom: (fn: (value: string) => boolean, message: string) => StringValidator |
| 274 | +} |
| 275 | + |
| 276 | +export interface NumberValidatorType extends Validator<number> { |
| 277 | + min: (min: number) => NumberValidator |
| 278 | + max: (max: number) => NumberValidator |
| 279 | + integer: (options?: IsIntOptions) => NumberValidator |
| 280 | + float: (options?: IsFloatOptions) => NumberValidator |
| 281 | + decimal: (options?: Parameters<typeof isDecimal>[1]) => NumberValidator |
| 282 | + positive: () => NumberValidator |
| 283 | + negative: () => NumberValidator |
| 284 | + divisibleBy: (divisor: number) => NumberValidator |
| 285 | + custom: (fn: (value: number) => boolean, message: string) => NumberValidator |
| 286 | +} |
| 287 | + |
| 288 | +export interface ArrayValidatorType<T> extends Validator<T[]>, LengthValidator<ArrayValidator<T>> { |
| 289 | + each: (validator: Validator<T>) => ArrayValidator<T> |
| 290 | + unique: () => ArrayValidator<T> |
| 291 | +} |
| 292 | + |
| 293 | +export interface BooleanValidatorType extends Validator<boolean> { |
| 294 | + isTrue: () => BooleanValidator |
| 295 | + isFalse: () => BooleanValidator |
| 296 | + custom: (fn: (value: boolean) => boolean, message: string) => BooleanValidator |
| 297 | +} |
| 298 | + |
| 299 | +export interface EnumValidatorType<T extends string | number> extends Validator<T> { |
| 300 | + custom: (fn: (value: T) => boolean, message: string) => EnumValidator<T> |
| 301 | +} |
| 302 | + |
| 303 | +export interface DateValidatorType extends Validator<Date> { |
| 304 | + // Base date validator is simple, just implements the base Validator interface |
| 305 | +} |
| 306 | + |
| 307 | +export interface DatetimeValidatorType extends Validator<Date> { |
| 308 | + // Datetime validator is simple, just implements the base Validator interface |
| 309 | +} |
| 310 | + |
| 311 | +export interface ObjectValidatorType<T extends Record<string, any>> extends Validator<T> { |
| 312 | + shape: (schema: Record<string, Validator<any>>) => ObjectValidator<T> |
| 313 | + strict: (strict?: boolean) => ObjectValidator<T> |
| 314 | +} |
| 315 | + |
| 316 | +export interface CustomValidatorType<T> extends Validator<T> { |
| 317 | + // Custom validator is simple, just implements the base Validator interface |
| 318 | +} |
| 319 | + |
| 320 | +export interface TimestampValidatorType extends Validator<number | string> { |
| 321 | + // Timestamp validator is simple, just implements the base Validator interface |
| 322 | +} |
| 323 | + |
| 324 | +export interface UnixValidatorType extends Validator<number | string> { |
| 325 | + // Unix validator is simple, just implements the base Validator interface |
| 326 | +} |
| 327 | + |
| 328 | +export interface PasswordValidatorType extends Validator<string> { |
| 329 | + matches: (confirmPassword: string) => PasswordValidator |
| 330 | + min: (length?: number) => PasswordValidator |
| 331 | + max: (length?: number) => PasswordValidator |
| 332 | + hasUppercase: () => PasswordValidator |
| 333 | + hasLowercase: () => PasswordValidator |
| 334 | + hasNumbers: () => PasswordValidator |
| 335 | + hasSpecialCharacters: () => PasswordValidator |
| 336 | + alphanumeric: () => PasswordValidator |
| 337 | +} |
| 338 | + |
256 | 339 | export interface ValidationInstance { |
257 | 340 | string: () => StringValidator |
258 | 341 | number: () => NumberValidator |
|
0 commit comments