UNPKG

bguard

Version:

**bguard** is a powerful, flexible, and type-safe validation library for TypeScript. It allows developers to define validation schemas for their data structures and ensures that data conforms to the expected types and constraints.

26 lines (23 loc) 1.05 kB
import { WithArray } from '../../commonTypes.mjs'; import { CommonSchema, ValidatorContext } from '../../core.mjs'; import '../../InferType.mjs'; import '../../helpers/constants.mjs'; /** * @description Creates a new schema for validating arrays where each element must match the specified schema. * @template T * @param {T} arraySchema - The schema that each element of the array must match. * @returns {WithArray<ArraySchema, T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema. * @example * const schema = array(string()); * parseOrFail(schema, ['hello', 'world']); // Validates successfully * parseOrFail(schema, ['hello', 123]); // Throws a validation error * * @instance Of ArraySchema */ declare function array<T extends CommonSchema>(arraySchema: T): WithArray<ArraySchema, T>; declare class ArraySchema extends CommonSchema { protected _array: number; constructor(ctx: ValidatorContext, arraySchema: CommonSchema); private validateArrayEntry; } export { array };