Security News
RubyGems.org Adds New Maintainer Role
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.
@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
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
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.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.