mcpField
J
joi

joi

github.com/damusixDevelopment6235 installsUpdated 1w ago
Repository

About joi

joi is a JavaScript schema-validation skill for developers who need to validate input and compose structured rules. It covers built-in types, conditional schemas, cross-field references, custom extensions, and error handling.

Key features

  1. 01Schema validation with validate() and attempt()
  2. 02Composable object, array, and alternatives schemas
  3. 03Conditional rules with .when()
  4. 04Cross-field references with Joi.ref()
  5. 05Custom types through Joi.extend()
  6. 06Custom validation error messages

Use cases

  1. 01Validating data at an application boundary
  2. 02Checking fields based on another field's value
  3. 03Ensuring confirmation fields match
  4. 04Adding domain-specific validation types

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/damusix/skills --skill joi

After installing, type/joiin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

.tessl-plugin/
plugin.json
reference/
any.md
conditionals.md
errors.md
extensions.md
metadata.md
references.md
testing.md
types.md
validation.md

Details

From the project README

Joi

Quick Start

const Joi = require('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

  1. Schemas are immutable - Every method returns a new schema instance; never mutate
  2. Validate at boundaries - Use validate() or attempt() at input boundaries; see validation
  3. Types extend base - All types inherit from any(); see types overview
  4. Refs for cross-field - Use Joi.ref() for dynamic values across fields; see references
  5. Extend for custom types - Use Joi.extend() to create custom types; see extensions

Workflow

  1. Choose a type - types overview for all built-in types
  2. Add constraints - Chain rules like .min(), .max(), .pattern(), .valid()
  3. Compose schemas - Nest Joi.object(), Joi.array(), Joi.alternatives()
  4. Add conditionals - Use .when() for dynamic schemas; see conditionals
  5. Customize errors - Override messages via .messages() or .error(); see errors

Common Patterns

Conditional validation with .when()
const schema = Joi.object({
    type: Joi.string().valid('email', 'sms').required(),
    address: Joi.when('type', {
        is: 'email',
        then: Joi.string().email().required(),
        otherwise: Joi.string().pattern(/^\+?[1-9]\d{1,14}$/).required()
    })
});
Cross-field references with Joi.ref()
const schema = Joi.object({
    password: Joi.string().min(8).required(),
    confirmPassword: Joi.string().valid(Joi.ref('password')).required()
        .messages({ 'any.only': 'passwords must match' }),
    startDate: Joi.date().required(),
    endDate: Joi.date().greater(Joi.ref('startDate')).required()
});

Key Patterns

TopicReference
All built-in typestypes
Validation & optionsvalidation
References & templatesreferences
Conditional schemasconditionals
Error handlingerrors
Custom extensionsextensions
Metadata & introspectionmetadata
Common methods (any)any
Testing patternstesting

Comments

Markdown supported