Socket
Socket
Sign inDemoInstall

joi

Package Overview
Dependencies
Maintainers
2
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

35

lib/types/base.js

@@ -39,3 +39,3 @@ // Load modules

this['type'] = this.__name;
this.type = this.__name;
}

@@ -211,6 +211,12 @@

var self = this;
if (this.__modifiers.has('required')) {
this.optional();
return this._xor(peers);
}
return function (value, obj, key, errors, keyPath) {
return !self._with(peers)(value, obj);
}
};
};

@@ -226,2 +232,27 @@

internals.BaseType.prototype._xor = function (peers) {
var self = this;
var withFn = self._with(peers);
return function (value, obj, key, errors, keyPath) {
var result = !!((typeof value !== 'undefined' && value !== null) ^ withFn(value, obj, key, errors, keyPath));
if (!result) {
errors.add('the value of `' + key + '` must exist without ' + peers, keyPath);
}
return result;
};
};
internals.BaseType.prototype.xor = function () {
this.add('xor', this._xor(Array.prototype.slice.call(arguments)), arguments);
return this;
};
internals.BaseType.prototype._renameDefaultOptions = {

@@ -228,0 +259,0 @@ deleteOrig: false,

2

lib/types/object.js

@@ -77,3 +77,3 @@ // Load modules

var itemConfig = config[key];
var value = obj ? obj[key] : null;
var value = obj[key];
keyPath = keyPath ? topKeyPath + '.' + key : key;

@@ -80,0 +80,0 @@

{
"name": "joi",
"description": "Object schema validation",
"version": "0.2.0",
"version": "0.2.1",
"author": "Van Nguyen <the.gol.effect@gmail.com>",

@@ -23,11 +23,7 @@ "contributors": [

"devDependencies": {
"mocha": "1.x.x",
"chai": "1.x.x",
"blanket": "1.0.x",
"travis-cov": "0.2.x"
"lab": "0.0.x",
"complexity-report": "0.x.x"
},
"scripts": {
"test": "make test && make test-cov",
"blanket": { "pattern": "//^((?!\/node_modules\/)(?!\/test\/).)*$/ig", "onlyCwd": true, "data-cover-flags": { "branchTracking": true } },
"travis-cov": { "threshold": 100 }
"test": "make test-cov"
},

@@ -34,0 +30,0 @@ "licenses": [

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../lib');

@@ -14,3 +14,7 @@

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;
var T = Joi.Types;

@@ -43,2 +47,12 @@

var config5 = {
txt: Joi.types.String().xor('upc'),
upc: Joi.types.String().xor('txt')
};
var config6 = {
txt: Joi.types.String().required().without('upc'),
upc: Joi.types.String().required().without('txt')
};
it('should validate object successfully', function (done) {

@@ -57,2 +71,32 @@

it('should validate null', function (done) {
var err = Joi.validate(null, config);
expect(err).to.exist;
done();
});
it('should validate xor statements', function (done) {
expect(Joi.validate({ upc: null }, config5)).to.not.be.null;
expect(Joi.validate({ upc: 'test' }, config5)).to.be.null;
expect(Joi.validate({ txt: null }, config5)).to.not.be.null;
expect(Joi.validate({ txt: 'test' }, config5)).to.be.null;
expect(Joi.validate({ upc: null, txt: null }, config5)).to.not.be.null;
expect(Joi.validate({ txt: 'test', upc: 'test' }, config5)).to.not.be.null;
done();
});
it('should validate required without statements like xor', function (done) {
expect(Joi.validate({ upc: null }, config6)).to.not.be.null;
expect(Joi.validate({ upc: 'test' }, config6)).to.be.null;
expect(Joi.validate({ txt: null }, config6)).to.not.be.null;
expect(Joi.validate({ txt: 'test' }, config6)).to.be.null;
expect(Joi.validate({ upc: null, txt: null }, config6)).to.not.be.null;
expect(Joi.validate({ txt: 'test', upc: 'test' }, config6)).to.not.be.null;
done();
});
it('should validate object successfully when config has an array of types', function (done) {

@@ -59,0 +103,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../lib');

@@ -15,3 +15,7 @@ var Set = require('../lib/set');

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;

@@ -18,0 +22,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');

@@ -13,3 +13,7 @@

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;

@@ -16,0 +20,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../../lib');

@@ -15,3 +15,7 @@ var Support = require('../support/meta');

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;
var verifyBehavior = Support.verifyValidatorBehavior;

@@ -18,0 +22,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../../lib');

@@ -14,3 +14,7 @@

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;

@@ -17,0 +21,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../../lib');

@@ -16,3 +16,7 @@ var Support = require('../support/meta');

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;

@@ -19,0 +23,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../../lib');

@@ -16,3 +16,7 @@ var FunctionType = require('../../lib/types/function');

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;
var verifyBehavior = Support.verifyValidatorBehavior;

@@ -19,0 +23,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../../lib');

@@ -14,3 +14,7 @@

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;

@@ -17,0 +21,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../../lib');

@@ -15,3 +15,7 @@ var Support = require('../support/meta');

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;
var verifyBehavior = Support.verifyValidatorBehavior;

@@ -18,0 +22,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../../lib');

@@ -16,3 +16,7 @@ var Object = require('../../lib/types/object');

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;
var verifyBehavior = Support.verifyValidatorBehavior;

@@ -19,0 +23,0 @@

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Joi = require('../../lib');

@@ -15,3 +15,7 @@ var Support = require('../support/meta');

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;
var verifyBehavior = Support.verifyValidatorBehavior;

@@ -241,2 +245,11 @@

it('should validate alphanum when allow spaces is null', function (done) {
var t = S().alphanum(null);
verifyBehavior(t, [
['w0rld of w4lm4rtl4bs', true],
['abcd#f?h1j orly?', false]
], done);
});
it('should validate email', function (done) {

@@ -243,0 +256,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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