Skip to content

Schema.list

Description

Validates that the provided value is an array whose items are validated by the given item validator. Supports enforcing minimum and maximum length constraints.

If the layout of the array is not important and item validation is not needed, use Schema.array instead.

Usage

ts
import * as Schema from "@bytelab.studio/schemify";

const schema = Schema.list(Schema.number());

schema.validate([1, 2, 3]);
schema.validate([1, "abc"]); // <-- throws SchemaError

Options

OptionsTypeDefaultDescription
minLengthnumberundefinedMinimum length of the array.
maxLengthnumberundefinedMaximum length of the array.

Definition

ts
export interface ListOptions extends RawOptions {
    minLenght?: number;
    maxLenght?: number;
}

Hierarchy