Socket
Socket
Sign inDemoInstall

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.8.2 to 0.8.3

6

lib/array.js

@@ -56,3 +56,4 @@ 'use strict';

schema,
endEarly;
endEarly,
recursive;

@@ -64,2 +65,3 @@ _state = _state || {};

endEarly = schema._option('abortEarly', _opts);
recursive = schema._option('recursive', _opts);

@@ -70,3 +72,3 @@ return MixedSchema.prototype._validate.call(this, _value, _opts, _state)['catch'](endEarly ? null : function (err) {

}).then(function (value) {
if (!subType || !schema._typeCheck(value)) {
if (!recursive || !subType || !schema._typeCheck(value)) {
if (errors.length) throw errors[0];

@@ -73,0 +75,0 @@ return value;

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

this._conditions = [];
this._options = { abortEarly: true };
this._options = { abortEarly: true, recursive: true };
this._exclusive = Object.create(null);

@@ -28,0 +28,0 @@ this._whitelist = new BadSet();

@@ -109,3 +109,4 @@ 'use strict';

schema,
endEarly;
endEarly,
recursive;

@@ -116,8 +117,9 @@ _state = _state || {};

endEarly = schema._option('abortEarly', _opts);
recursive = schema._option('recursive', _opts);
return MixedSchema.prototype._validate.call(this, _value, _opts, _state)['catch'](endEarly ? null : function (err) {
errors = err;
errors.push(err);
return err.value;
}).then(function (value) {
if (!isObject(value)) {
if (!recursive || !isObject(value)) {
// only iterate though actual objects

@@ -161,3 +163,3 @@ if (errors.length) throw errors[0];

next._excludedEdges = next._excludedEdges.concat(excludes.map(function (v) {
if (excludes.length) next._excludedEdges = next._excludedEdges.concat(excludes.map(function (v) {
return '' + v[0] + '-' + v[1];

@@ -208,3 +210,3 @@ })); // 'node-othernode'

if (!!noAllow) this._options.stripUnknown = true;
if (noAllow) this._options.stripUnknown = true;

@@ -211,0 +213,0 @@ return next;

{
"name": "yup",
"version": "0.8.2",
"version": "0.8.3",
"description": "Dead simple Object schema validation",

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

@@ -143,5 +143,3 @@ Yup

Returns the value (a cast value if `isStrict` is `false`) if the value is valid, and returns the errors otherwise. This method is __asynchronous__
and returns a Promise object, that is fulfilled with the value, or rejected with a `ValidationError`. If you are more comfortable with
Node style callbacks, then you can provide one to be called when the validation is complete (called with the Error as the first argument, and value
Returns the value (a cast value if `isStrict` is `false`) if the value is valid, and returns the errors otherwise. This method is __asynchronous__ and returns a Promise object, that is fulfilled with the value, or rejected with a `ValidationError`. If you are more comfortable with Node style callbacks, then you can provide one to be called when the validation is complete (called with the Error as the first argument, and value
as the second).

@@ -184,3 +182,5 @@

- `abortEarly` -> boolean: default `true`, return from validation methods on the first error rather than after all validations run.
- `context` -> an object hash containing any context for validating schema conditions (see: `when()`)
- `stripUnknown` -> boolean: default `false` remove unspecified keys from objects.
- `recursive` -> boolean: default `true` when `false` validations will not descend into sub schemas (relavant for objects or arrays).
- `context` -> an `object` containing any context for validating schema conditions (see: `when()`)

@@ -187,0 +187,0 @@ #### `mixed.cast(value)`

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

})
}

@@ -45,10 +44,12 @@

var errors = []
, context, subType, schema, endEarly;
, context, subType, schema, endEarly, recursive;
_state = _state || {}
context = _state.parent || (_opts || {}).context
schema = this._resolve(context)
subType = schema._subType
endEarly = schema._option('abortEarly', _opts)
_state = _state || {}
context = _state.parent || (_opts || {}).context
schema = this._resolve(context)
subType = schema._subType
endEarly = schema._option('abortEarly', _opts)
recursive = schema._option('recursive', _opts)
return MixedSchema.prototype._validate.call(this, _value, _opts, _state)

@@ -60,3 +61,3 @@ .catch(endEarly ? null : err => {

.then(function(value){
if ( !subType || !schema._typeCheck(value) ) {
if ( !recursive || !subType || !schema._typeCheck(value) ) {
if ( errors.length ) throw errors[0]

@@ -63,0 +64,0 @@ return value

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

this._conditions = []
this._options = { abortEarly: true }
this._options = { abortEarly: true, recursive: true }
this._exclusive = Object.create(null)

@@ -25,0 +25,0 @@ this._whitelist = new BadSet()

@@ -105,8 +105,9 @@ 'use strict';

var errors = []
, context, schema, endEarly;
, context, schema, endEarly, recursive;
_state = _state || {}
context = _state.parent || (_opts || {}).context
schema = this._resolve(context)
endEarly = schema._option('abortEarly', _opts)
_state = _state || {}
context = _state.parent || (_opts || {}).context
schema = this._resolve(context)
endEarly = schema._option('abortEarly', _opts)
recursive = schema._option('recursive', _opts)

@@ -116,7 +117,7 @@ return MixedSchema.prototype._validate

.catch(endEarly ? null : err => {
errors = err
errors.push(err)
return err.value
})
.then(value => {
if(!isObject(value)) {// only iterate though actual objects
if( !recursive || !isObject(value)) { // only iterate though actual objects
if ( errors.length ) throw errors[0]

@@ -162,4 +163,5 @@ return value

next._excludedEdges = next._excludedEdges.concat(
excludes.map(v => `${v[0]}-${v[1]}`)) // 'node-othernode'
if ( excludes.length )
next._excludedEdges = next._excludedEdges.concat(
excludes.map(v => `${v[0]}-${v[1]}`)) // 'node-othernode'

@@ -198,3 +200,3 @@ next._nodes = sortFields(fields, next._excludedEdges)

if ( !!noAllow )
if ( noAllow )
this._options.stripUnknown = true

@@ -201,0 +203,0 @@

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

var inst = object().shape({
child: "$this",
child: '$this',
other: string().required('required!')

@@ -203,3 +203,3 @@ })

err.errors[0].should.equal('required!')
}),
})

@@ -216,19 +216,17 @@ ])

})
// var inst = object({
// str: string().required()
// })
// .test('name', 'oops', function(v){ return false })
return Promise.all([
inst.validate({ nest: { str: null } }).should.be.rejected
.then(function(err){
//console.log(err)
inst
.validate({ nest: { str: null } }).should.be.rejected
.then(function(err) {
err.value.should.eql({ nest: { str: '' } })
err.errors.length.should.equal(1)
err.errors.should.eql(['oops'])
err.path.should.equal('nest')
}),
inst.validate({ nest: { str: null } }, { abortEarly: false }).should.be.rejected
.then(function(err){
//console.log(err)
inst
.validate({ nest: { str: null } }, { abortEarly: false }).should.be.rejected
.then(function(err) {
err.value.should.eql({ nest: { str: '' } })

@@ -241,2 +239,30 @@ err.errors.length.should.equal(2)

it('should respect recursive', function(){
var inst = object({
nest: object({
str: string().required()
})
})
.test('name', 'oops', function(){ return false })
var val = { nest: { str: null } };
return Promise.all([
inst
.validate(val, { abortEarly: false }).should.be.rejected
.then(function(err){
err.errors.length.should.equal(2)
}),
inst
.validate(val, { abortEarly: false, recursive: false }).should.be.rejected
.then(function(err){
err.errors.length.should.equal(1)
err.errors.should.eql(['oops'])
})
])
})
it('should alias or move keys', function(){

@@ -243,0 +269,0 @@ var inst = object().shape({

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