Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@types/yup
Advanced tools
Stub TypeScript definitions entry for yup, which provides its own types definitions
@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.
This is a stub types definition for @types/yup (https://github.com/jquense/yup).
yup provides its own type definitions, so you don't need @types/yup installed!
FAQs
Stub TypeScript definitions entry for yup, which provides its own types definitions
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.