joi
Original:🇺🇸 English
Translated
Use when building joi schemas, custom validators, extensions, or working with joi's validation pipeline. Covers all types, references, templates, errors, and the extension API.
1installs
Sourcedamusix/skills
Added on
NPX Install
npx skill4agent add damusix/skills joiTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Joi
Quick Start
const Joi = require('@hapi/joi');
const schema = Joi.object({
name: Joi.string().min(1).max(100).required(),
age: Joi.number().integer().min(0),
email: Joi.string().email()
});
const { error, value } = schema.validate(input);Critical Rules
- Schemas are immutable - Every method returns a new schema instance; never mutate
- Validate at boundaries - Use or
validate()at input boundaries; see validationattempt() - Types extend base - All types inherit from ; see types overview
any() - Refs for cross-field - Use for dynamic values across fields; see references
Joi.ref() - Extend for custom types - Use to create custom types; see extensions
Joi.extend()
Workflow
- Choose a type - types overview for all built-in types
- Add constraints - Chain rules like ,
.min(),.max(),.pattern().valid() - Compose schemas - Nest ,
Joi.object(),Joi.array()Joi.alternatives() - Add conditionals - Use for dynamic schemas; see conditionals
.when() - Customize errors - Override messages via or
.messages(); see errors.error()
Key Patterns
| Topic | Reference |
|---|---|
| All built-in types | types |
| Validation & options | validation |
| References & templates | references |
| Conditional schemas | conditionals |
| Error handling | errors |
| Custom extensions | extensions |
| Metadata & introspection | metadata |
| Common methods (any) | any |
| Testing patterns | testing |