Validate
Library
Updated 2 months ago ·
v1.3.7i
Shared Module
Build validation chains to assert value types, ranges, and custom constraints.
validate
Creates a new validation chain for a value.
Methods
| Method | Parameters | Description |
|---|---|---|
.string(len?) | len: number — optional max length | Assert value is a string |
.number() | — | Assert value is a number |
.boolean() | — | Assert value is a boolean |
.min(min) | min: number | Minimum value (number) or minimum length (string) |
.max(max) | max: number | Maximum value (number) or maximum length (string) |
.refine(fn, err?) | fn: function(value) → boolean, err: string | Custom validation function |
.default(value) | value: any | Use this value if the input is nil |
.done() | — | Finalize and return the raw value |
The chain can also be called directly — validate(x).string()() is equivalent to .done().
Example
Was this page helpful?
This page was last updated on 12 March 2026