UNPKG

ts-valid8

Version:

A next-generation TypeScript validation library with advanced features

85 lines 3.17 kB
import { BaseSchema } from '../core/schema'; import { Schema, ValidationContext, ValidationResult } from '../core/types'; /** * ArraySchema - Advanced array validation with unique features * Supports element validation, array operations, and advanced array-specific rules */ export declare class ArraySchema<T> extends BaseSchema<T[]> { _type: string; private _elementSchema?; constructor(elementSchema?: Schema<T>); protected validateType(value: unknown, context: ValidationContext): ValidationResult<T[]>; protected clone(): ArraySchema<T>; /** * Validate each element of the array with the specified schema */ of<U>(schema: Schema<U>): ArraySchema<U>; /** * Require the array to have a minimum length */ min(length: number, message?: string): ArraySchema<T>; /** * Require the array to have a maximum length */ max(length: number, message?: string): ArraySchema<T>; /** * Require the array to have an exact length */ length(length: number, message?: string): ArraySchema<T>; /** * Require the array to not be empty */ nonEmpty(message?: string): ArraySchema<T>; /** * Require all elements in the array to be unique * Provides options for deep comparison of objects and custom equality functions * Unique feature not commonly found in other libraries */ unique(options?: { message?: string; path?: string; comparator?: (a: any, b: any) => boolean; }): ArraySchema<T>; /** * Require all elements to satisfy a predicate function * More flexible than simple validation with element schema */ every(predicate: (item: T) => boolean, message: string | ((item: T, index: number) => string)): ArraySchema<T>; /** * Require at least one element to satisfy a predicate function */ some(predicate: (item: T) => boolean, message?: string): ArraySchema<T>; /** * Sort check - verify if array is sorted according to comparator function * Unique feature not found in most validation libraries */ sorted(options?: { comparator?: (a: T, b: T) => number; message?: string; strictlyIncreasing?: boolean; }): ArraySchema<T>; /** * No sparse elements (no empty slots) * Unique validation not found in most libraries */ noSparse(message?: string): ArraySchema<T>; /** * Validate array contains specific elements * Unique validation for checking presence of elements in arrays */ contains<V>(element: V, options?: { message?: string; comparator?: (a: any, b: V) => boolean; }): ArraySchema<T>; /** * Validate that array contains no duplicate values * Similar to unique but with more descriptive name and simpler API */ noDuplicates(message?: string): ArraySchema<T>; /** * Validate that array items follow a specific schema order * Unique feature for validating tuples with specific sequence of item types */ ordered(schemas: Schema<any>[], message?: string): ArraySchema<any>; } //# sourceMappingURL=array.d.ts.map