Portable and simple schemas for property validation.
- Easy and understandable schemas
- Contains ready regex patterns
- Portable schemas as a JSON file
- Schemas can be declared for TypeScript
- Schemas can be converted to JSON Schema. JSON Schema is OpenAPI compatible
- Error messages are ready to be understood but can be edited if desired
- Works with Yup, stable and secure
You can install it as follows.
# NPM
npm add yuppi
# PNPM
pnpm add yuppi
# Yarn
yarn add yuppi
# Bun
bun add yuppi
# Deno
deno add yuppiBriefly as follows.
yuppi
│
├── new Yuppi(options?)
│ │
│ ├── validate(schema, properties)
│ ├── declare(schema, name)
│ ├── convertToYup(schema)
│ └── convertToJSONSchema(schema)
│
├── Patterns
│ │
│ ├── Domain
│ ├── Email
│ ├── HTTP
│ ├── PhoneNumber
│ ├── URI
│ └── Username
│
├── type AnyObject
├── type JSONSchema
├── type Schema
├── type ValidationError
├── type YuppiOptions
└── type YupSchemaBriefly as follows.
import { Yuppi, Patterns } from 'yuppi';new Yuppi(options?)
Yuppi schema builder.
Parameter Type Default Description options?YuppiOptions YuppiOptionsDefault Constructor's options. Example:
const Yupp = new Yuppi();
Yuppi.validate(schema, properties)
Validate the properties with your Yuppi schema.
Parameter Type Default Description schemaSchema Yuppi schema. propertiesAnyObject Properties to be validate. Example:
const schema: Schema = { display_name: { type: 'string', max: 32, nullable: false, required: true }, username: { type: 'string', min: 3, max: 16, pattern: Patterns.Username, nullable: false, required: true }, email: { type: 'string', pattern: Patterns.Email, lowercase: true, nullable: false, required: true }, permissions: [ { type: 'string', enum: ['*'], nullable: false, required: true }, { type: 'array', items: { type: 'string', enum: ['read', 'write'], nullable: false, required: true }, nullable: false, required: true } ] }; const properties = { display_name: 'Fırat', username: 'fir4tozden', email: 'fir4tozden@gmail.com', permissions: '*' }; try { await Yupp.validate(schema, properties); /* { display_name: "Fırat", username: "fir4tozden", email: "fir4tozden@gmail.com", permissions: "*" } */ } catch (error) { const errors = (error as ValidationError).errors; console.log(errors[0]); // "Field email must match the required pattern ^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$" }
Yuppi.declare(schema, name)
Declare your Yuppi schema for TypeScript.
Parameter Type Default Description schemaSchema Yuppi schema. nameString Declaration name. Example:
import type { User } from './generated/yuppi/types/User'; await Yupp.declare(schema, 'User'); const user = (await Yupp.validate(schema, properties)) as User; /* interface User { display_name: string; username: string; email: string; permissions: "*" | ("read" | "write")[]; } */
Yuppi.convertToYup(schema)
Convert your Yuppi schema into Yup schema.
Parameter Type Default Description schemaSchema Yuppi schema. returns YupSchema
Example:
Yupp.convertToYup(schema);
Yuppi.convertToJSONSchema(schema)
Convert your Yuppi schema into JSON Schema.
Parameter Type Default Description schemaSchema Yuppi schema. returns JSONSchema
Example:
Yupp.convertToJSONSchema(schema); /* { type: "object", properties: { display_name: { type: "string", maxLength: 32 }, username: { type: "string", minLength: 3, maxLength: 16, pattern: "^(?=.*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9_]*$" }, email: { type: "string", pattern: "^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$" }, permissions: { anyOf: [ { type: "string", enum: ["*"] }, { type: "array", items: { type: "string", enum: ["read", "write"] } } ] } }, required: ["display_name", "username", "email", "permissions"], additionalProperties: false }; */
| Pattern | Description | Examples |
|---|---|---|
| Domain | Domains. | "google.com" ✅"www.google.com" ✅"https://google.com" ❌ |
| Emails. | "fir4tozden@gmail.com" ✅"fir4tozden+2@gmail.com" ❌ |
|
| HTTP | HTTP only links. | "https://google.com" ✅"http://google.com" ✅"google.com" ❌ |
| PhoneNumber | Country code and phone number. | "0090-555555555" ✅"90-5555555555" ❌ |
| URI | Protocol free links. | "mongodb://mongodb.net" ✅"https://google.com" ✅"google.com" ❌ |
| Username | Usernames like Twitter. | "fir4tozden" ✅"Fir4tozden" ✅"fir4t ozden" ❌ |
| Type |
|---|
| AnyObject |
| JSONSchema |
| Schema |
| ValidationError |
| YuppiOptions |
| YupSchema |
MIT License
Copyright (c) 2025 Keift
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
