Skip to content
OpenSmartRoute
Skillv1.0.0

yup

Validate data with Yup schemas. Use when adding form validation, defining API request schemas, validating configuration, or building type-safe validation pipelines in JavaScript/TypeScript.

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/yup/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill yup. Copyright stays with the author (Apache-2.0).

Yup

Overview

Yup is a schema validation library for JavaScript. Define schemas declaratively, validate data, and get detailed error messages. Works with Formik, react-hook-form, and standalone. TypeScript-first with type inference.

Instructions

Step 1: Schemas

import * as yup from 'yup'

const userSchema = yup.object({
  name: yup.string().min(2).max(100).required(),
  email: yup.string().email().required(),
  age: yup.number().positive().integer().min(13).max(120),
  role: yup.string().oneOf(['admin', 'member', 'viewer']).default('member'),
  tags: yup.array().of(yup.string()).min(1).max(10),
  address: yup.object({
    street: yup.string().required(),
    city: yup.string().required(),
    zip: yup.string().matches(/^\d{5}$/, 'Must be 5 digits'),
  }),
})

// Validate
const user = await userSchema.validate(data, { abortEarly: false })

// Type inference
type User = yup.InferType<typeof userSchema>

Step 2: Custom Validation

const passwordSchema = yup.string()
  .min(8)
  .matches(/[A-Z]/, 'Must contain uppercase')
  .matches(/[0-9]/, 'Must contain number')
  .matches(/[^A-Za-z0-9]/, 'Must contain special character')

const signupSchema = yup.object({
  password: passwordSchema.required(),
  confirmPassword: yup.string()
    .oneOf([yup.ref('password')], 'Passwords must match')
    .required(),
})

Step 3: Conditional Validation

const schema = yup.object({
  contactMethod: yup.string().oneOf(['email', 'phone']).required(),
  email: yup.string().when('contactMethod', {
    is: 'email',
    then: (s) => s.email().required('Email required when contact method is email'),
  }),
  phone: yup.string().when('contactMethod', {
    is: 'phone',
    then: (s) => s.matches(/^\+\d{10,15}$/).required('Phone required'),
  }),
})

Guidelines

  • abortEarly: false returns all errors at once — better UX than one-at-a-time.
  • Use InferType to derive TypeScript types from schemas — single source of truth.
  • For new projects, consider Zod instead — better TypeScript inference and ecosystem.
  • Yup is still the standard for Formik integration.
  • .when() for conditional validation — fields required only in certain contexts.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-yup/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-yup.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-yup",
  "kind": "skill",
  "name": "yup",
  "description": "Validate data with Yup schemas. Use when adding form validation, defining API request schemas, validating configuration, or building type-safe validation pipelines in JavaScript/TypeScript.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "yup",
      "validation",
      "schema",
      "forms",
      "typescript",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Validate data with Yup schemas. Use when adding form validation, defining API request schemas, validating configuration, or building type-safe validation pipelines in JavaScript/TypeScript."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/yup/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/yup/SKILL.md",
      "key": "terminalskills/skills/skills/yup/SKILL.md"
    },
    "compatibility": "Any JavaScript runtime",
    "license": "Apache-2.0"
  },
  "instructions": "# Yup\n\n## Overview\n\nYup is a schema validation library for JavaScript. Define schemas declaratively, validate data, and get detailed error messages. Works with Formik, react-hook-form, and standalone. TypeScript-first with type inference.\n\n## Instructions\n\n### Step 1: Schemas\n\n```typescript\nimport * as yup from 'yup'\n\nconst userSchema = yup.object({\n  name: yup.string().min(2).max(100).required(),\n  email: yup.string().email().required(),\n  age: yup.number().positive().integer().min(13).max(120),\n  role: yup.string().oneOf(['admin', 'member', 'viewer']).default('member'),\n  tags: yup.array().o",
  "cost": {
    "context_tokens": 556
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-yup/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.