Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@types/yup
Advanced tools
@types/yup provides TypeScript type definitions for the Yup library, which is a JavaScript schema builder for value parsing and validation.
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']
});
Joi is a powerful schema description language and data validator for JavaScript. It is similar to Yup in that it allows you to define schemas and validate data against them. However, Joi is often considered more feature-rich and is commonly used in Node.js applications.
Ajv is a JSON schema validator that is highly performant and supports JSON Schema standards. Unlike Yup, which is more focused on JavaScript object validation, Ajv is designed for validating JSON data and is often used in APIs and configuration validation.
Superstruct is a library for validating data structures in JavaScript. It is similar to Yup but offers a more functional approach to schema definition and validation. Superstruct is lightweight and can be a good alternative for projects that prefer functional programming paradigms.
npm install --save @types/yup
This package contains type definitions for yup (https://github.com/jquense/yup).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/yup.
These definitions were written by Dominik Hardtke, Vladyslav Tserman, Moreton Bay Regional Council, Sindre Seppola, Yash Kulshrestha, Vincent Pizzo, Robert Bullen, Yusuke Sato, Desmond Koh, Maurice de Beijer, Kalley Powell, and Elías García.
FAQs
Stub TypeScript definitions entry for yup, which provides its own types definitions
The npm package @types/yup receives a total of 0 weekly downloads. As such, @types/yup popularity was classified as not popular.
We found that @types/yup demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.