Rod

Arrays

Validating lists and collections.

Arrays

Arrays validate that every item in a list matches a specific schema.

use rod_rs::array;

let schema = array(string()).min(1).max(10);
import { rod } from 'rod-js';

const schema = rod.array(rod.string()).min(1).max(10);
import rod

schema = rod.array(rod.string()).min(1).max(10)

Batch Optimization (TypeScript)

When validating thousands of items in JavaScript, crossing the WASM bridge for every item is expensive. Rod provides a batch API to validate a whole array in one trip.

const schema = rod.string().email();
const largeArray = ["a@b.com", "invalid", "c@d.com"];

// Returns a bitmask: Uint8Array([1, 0, 1])
const mask = schema.checkBatch(largeArray);

// Filter the original array using the mask
const validItems = largeArray.filter((_, i) => mask[i] === 1);

On this page