Socket
Socket
Sign inDemoInstall

@types/yup

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/yup

TypeScript definitions for yup


Version published
Weekly downloads
824K
decreased by-0.94%
Maintainers
1
Weekly downloads
 
Created

What is @types/yup?

@types/yup provides TypeScript type definitions for the Yup library, which is a JavaScript schema builder for value parsing and validation.

What are @types/yup's main functionalities?

Schema Validation

This feature allows you to define a schema and validate an object against it. The schema can include various types and validation rules.

const yup = require('yup');

const schema = yup.object().shape({
  name: yup.string().required(),
  age: yup.number().required().positive().integer(),
});

schema.isValid({
  name: 'John Doe',
  age: 30
}).then(function(valid) {
  console.log(valid); // true
});

Asynchronous Validation

Yup supports asynchronous validation, which is useful for validating data that requires asynchronous operations, such as checking if an email is already in use.

const yup = require('yup');

const schema = yup.object().shape({
  email: yup.string().email().required(),
});

schema.validate({
  email: 'not-an-email'
}).catch(function(err) {
  console.log(err.errors); // ['email must be a valid email']
});

Custom Validation

You can define custom validation rules using the `test` method. This allows for more complex validation logic that is not covered by the built-in methods.

const yup = require('yup');

const schema = yup.object().shape({
  password: yup.string().required().min(8).test('is-strong', 'Password is not strong enough', value => {
    return /[A-Z]/.test(value) && /[0-9]/.test(value);
  })
});

schema.validate({
  password: 'weakpass'
}).catch(function(err) {
  console.log(err.errors); // ['Password is not strong enough']
});

Other packages similar to @types/yup

FAQs

Package last updated on 11 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc