yup

v1.7.1 MIT

Dead simple Object schema validation

Weekly Downloads
8.0M
Stars
23.7K
Forks
940
Open Issues
240
Gzip Size
14.2 kB
Unpacked Size
270.4 kB
Dependencies
4
Last Updated
6mo ago

yup Download Trends

Download trends for yup011.5M23.1M34.6M46.2MFeb 2025MayAugNovFebApr 2026
yup

About yup

Yup is a JavaScript schema builder for value validation and type casting. It addresses the common need for robust data validation in applications, particularly for incoming data from user interfaces, APIs, or configuration files. By defining expected data shapes and rules, Yup helps prevent runtime errors and ensures data integrity.

The core philosophy behind Yup is to provide a declarative and intuitive way to define schemas. It aims to be a developer-friendly tool, enabling the creation of complex validation logic with minimal boilerplate. This makes it suitable for developers working with dynamic data where strict type enforcement is crucial.

Key API patterns include the fluent interface for building schemas, such as `object().shape()`, `string().email()`, and `number().min()`. Yup supports various data types and a wide range of validation methods like required fields, email formats, min/max values, and custom validation functions. The `validate()` and `validateSync()` methods are central to its usage for checking data against a defined schema.

Yup integrates seamlessly into various JavaScript environments and workflows. It's commonly used in front-end frameworks like React and Vue for form validation, and in Node.js back-ends for validating API request bodies. It pairs well with serialization libraries and can be used within build pipelines or testing frameworks to ensure data consistency.

With a substantial weekly download count of 9.5 million and 23.7K GitHub stars, Yup is a mature and widely adopted library. Its unpacked size is 270.4 kB, with a gzipped bundle size of just 14.2 kB, indicating a relatively lean footprint for its capabilities.

While powerful, Yup's primary focus is on object schema validation. For highly specialized or extremely performance-critical validation scenarios that do not involve complex object structures, developers might explore alternative, more specialized libraries. Its extensibility is generally good, but complex custom logic may require careful implementation.

When to use

  • When validating form input data in React, Vue, or Angular applications using `object().shape()` to define field requirements and formats.
  • When ensuring data integrity for API request payloads in Node.js environments by defining schemas with `string().email()` or `number().positive()`.
  • When performing type casting and validation of configuration files before application startup.
  • When creating reusable validation logic for different parts of an application or across multiple projects.
  • When leveraging its fluent API to build complex validation rules, such as nested objects and array validations with `array().of()`.
  • When you need to validate data against a predefined schema before processing it further in asynchronous operations using `validate()`.

When NOT to use

  • If you only need to check for the existence of a value, JavaScript's truthiness check (`if (value)`) is sufficient and avoids an additional dependency.
  • If your validation needs are limited to simple primitive type checks without complex rules, consider native JavaScript type checking or a more specialized, lighter validation utility.
  • When dealing with highly specialized binary data formats where byte-level validation is required, as Yup is optimized for JSON-like structures.
  • If you are working in an environment with extremely strict Content Security Policy (CSP) limitations that might interfere with dynamic schema evaluation, although common use cases are generally fine.
  • When you need to validate data structures that are inherently deeply recursive or violate typical object graph limitations, which could lead to performance issues with `validate()`.

yup Alternatives

yup Categories