Overview
Bunli provides runtime validation utilities that work with Standard Schema v1 compatible schemas (like Zod). These functions validate command options, provide helpful error messages, and support custom validation logic.Core Functions
validateValue
Validate a single value against a schema at runtime.
value: The value to validateschema: A Standard Schema v1 compatible schema (e.g., Zod schema)context.option: The name of the option being validatedcontext.command: The command name for error context
BunliValidationError if validation fails
Example:
validateValues
Validate multiple values against their schemas in batch.
values: Object mapping option names to valuesschemas: Object mapping option names to schemascommand: The command name for error context
Error with all validation errors concatenated
Example:
isValueOfType
Check if a value matches a schema type without throwing errors.
value: The value to checkexpectedType: One of:'string','number','boolean','array','object'
true if the value matches the type
Example:
Validator Factories
createValidator
Create a reusable validator function from a schema.
createBatchValidator
Create a reusable batch validator for multiple options.
Error Types
BunliValidationError
Thrown when validation fails. Contains detailed context about the failure.
Properties:
message: Human-readable error messageoption: The option name that failed validationvalue: The invalid valuecommand: The command nameexpectedType: The expected type (e.g., ‘string’, ‘number’)hint: Helpful hint for fixing the error
Usage in Commands
Bunli automatically validates command options using these utilities. You typically don’t need to call them directly:See Also
- Error Handling - Error classes and patterns
- Option API - Define command options
- Command API - Define commands