Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yup

Package Overview
Dependencies
Maintainers
1
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yup - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

29

lib/mixed.js

@@ -24,3 +24,2 @@ 'use strict';

this._deps = [];
this._conditions = [];
this._options = { abortEarly: true, recursive: true };

@@ -92,3 +91,3 @@ this._exclusive = Object.create(null);

return this._conditions.reduce(function (schema, match) {
return this._deps.reduce(function (schema, match) {
return match.resolve(schema, match.getValue(parent, context));

@@ -263,27 +262,11 @@ }, schema);

return next
// function validate(value, path, context) {
// return new Promise((resolve, reject) => {
// !opts.useCallback
// ? resolve(opts.test.call(this, value, path, context))
// : opts.test.call(this, value, path, context, (err, valid) => err ? reject(err) : resolve(valid))
// })
// .then(validOrError => {
// if ( ValidationError.isError(validOrError) )
// throw normalizeError(validOrError, errorMsg, opts.params, path, value)
// else if (!validOrError)
// throw new ValidationError(errorMsg({ path, ...opts.params }), path, value)
// })
// }
;
return next;
}),
when: function when(key, options) {
var next = this.clone();
var next = this.clone(),
dep = new Condition(key, next._type, options);
next._deps.push(key);
next._conditions.push(new Condition(key, next._type, options));
next._deps.push(dep);
return next;

@@ -290,0 +273,0 @@ },

@@ -245,6 +245,8 @@ 'use strict';

fields[key]._deps && fields[key]._deps.forEach(function (node) {
fields[key]._deps && fields[key]._deps.forEach(function (dep) {
//eslint-disable-line no-loop-func
node = split(node)[0];
if (dep.isContext) return;
var node = split(dep.key)[0];
if (! ~nodes.indexOf(node)) nodes.push(node);

@@ -251,0 +253,0 @@

{
"name": "yup",
"version": "0.9.0",
"version": "0.9.1",
"description": "Dead simple Object schema validation",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Yup
=======================
Yup is a js object schema validator and object parser. The api and style is heavily inspired by [Joi](https://github.com/hapijs/joi), which is an amazing library but is often too large and diffucult to package for use in a browser. Yup is a leaner in the same spirit without the fancy features. You can use it on the server as well, but in that case you might as well just use Joi.
Yup is a js object schema validator and object parser. The api and style is heavily inspired by [Joi](https://github.com/hapijs/joi), which is an amazing library but is generally too large and difficult to package for use in a browser. Yup is a leaner in the same spirit without some of the fancy features. You can use it on the server as well, but in that case you might as well just use Joi.
Yup is also a a good bit less opinionated than joi, allowing for custom validation and transformations. It also allows "stacking" conditions via `when` for properties that depend on more than one other sibling or child property. Yup also also seperates the parsing and validating functions into seperate steps so it can be used to parse json seperate from validating it, via the `cast` method.
Yup is also a a good bit less opinionated than joi, allowing for custom transformations and async validation. It also allows "stacking" conditions via `when` for properties that depend on more than one other sibling or child property. Yup seperates the parsing and validating functions into seperate steps so it can be used to parse json seperate from validating it, via the `cast` method.

@@ -18,5 +18,5 @@ ## Usage

+ [`object`](#array)
- [`reach`](#reach)
- [`addMethod`](#addMethod)
- [`ValidationError`](#ValidationError)
- [`reach`](#reachschema-schema-string-path-object-options)
- [`addMethod`](#addmethodschematype-name-method)
- [`ValidationError`](#validationerrorstringarraystring-errors-string-path-any-value)
- [Extending Schema Types](#extending-schema-types)

@@ -77,3 +77,3 @@

### `.reach(Schema schema, String path, Object options)`
#### `.reach(Schema schema, String path, Object options)`

@@ -97,3 +97,3 @@ For nested schema's `yup.reach` will retrieve a nested schema based on the provided path.

### `.addMethod(schemaType, name, method)`
#### `.addMethod(schemaType, name, method)`

@@ -116,3 +116,3 @@ Adds a new method to the core schema types. A friendlier convenience method for `schemaType.prototype[name] = method`.

### `ValidationError(String|Array<String> errors, String path, Any value)`
#### `ValidationError(String|Array<String> errors, Any value, String path)`

@@ -119,0 +119,0 @@ Thrown on failed validations, with the following properties

@@ -21,3 +21,2 @@ 'use strict';

this._deps = []
this._conditions = []
this._options = { abortEarly: true, recursive: true }

@@ -92,5 +91,4 @@ this._exclusive = Object.create(null)

return this._conditions.reduce(function(schema, match){
return match.resolve(schema, match.getValue(parent, context))
}, schema)
return this._deps.reduce((schema, match) =>
match.resolve(schema, match.getValue(parent, context)), schema)
},

@@ -252,25 +250,10 @@

return next
// function validate(value, path, context) {
// return new Promise((resolve, reject) => {
// !opts.useCallback
// ? resolve(opts.test.call(this, value, path, context))
// : opts.test.call(this, value, path, context, (err, valid) => err ? reject(err) : resolve(valid))
// })
// .then(validOrError => {
// if ( ValidationError.isError(validOrError) )
// throw normalizeError(validOrError, errorMsg, opts.params, path, value)
// else if (!validOrError)
// throw new ValidationError(errorMsg({ path, ...opts.params }), path, value)
// })
// }
},
when(key, options){
var next = this.clone();
var next = this.clone()
, dep = new Condition(key, next._type, options);
next._deps.push(key)
next._conditions.push(new Condition(key, next._type, options))
next._deps.push(dep)
return next

@@ -316,2 +299,3 @@ },

var aliases = {

@@ -318,0 +302,0 @@ oneOf: ['equals', 'is'],

@@ -227,5 +227,8 @@ 'use strict';

fields[key]._deps &&
fields[key]._deps.forEach(node => { //eslint-disable-line no-loop-func
node = split(node)[0]
fields[key]._deps.forEach(dep => { //eslint-disable-line no-loop-func
if (dep.isContext)
return
var node = split(dep.key)[0]
if ( !~nodes.indexOf(node) )

@@ -232,0 +235,0 @@ nodes.push(node)

@@ -316,3 +316,3 @@ 'use strict';

.then(function(){
inst = string().when('prop', {
inst = string().when('$prop', {
is: function(val) { return val === 5 },

@@ -329,3 +329,10 @@ then: string().required(),

})
})
it('should not use context refs in object calculations', function(){
var inst = object({
prop: string().when('$prop', { is: 5, then: string().required('from context') })
})
inst.default().should.eql({ prop: undefined })
})

@@ -332,0 +339,0 @@

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