Socket
Socket
Sign inDemoInstall

@types/yup

Package Overview
Dependencies
0
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/yup


Version published
Maintainers
1
Install size
18.4 kB
Created

Package description

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

Readme

Source

Installation

npm install --save @types/yup

Summary

This package contains type definitions for yup ( https://github.com/jquense/yup ).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/yup

Additional Details

  • Last updated: Mon, 10 Jun 2019 17:20:21 GMT
  • Dependencies: none
  • Global values: none

Credits

These definitions were written by Dominik Hardtke https://github.com/dhardtke, Vladyslav Tserman https://github.com/vtserman, Moreton Bay Regional Council https://github.com/MoretonBayRC, Sindre Seppola https://github.com/sseppola, Yash Kulshrestha https://github.com/YashdalfTheGray, Vincent Pizzo https://github.com/vincentjames501, Robert Bullen https://github.com/robertbullen, Yusuke Sato https://github.com/sat0yu, Dan Rumney https://github.com/dancrumb, Desmond Koh https://github.com/deskoh, Maurice de Beijer https://github.com/mauricedb.

FAQs

Last updated on 10 Jun 2019

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc