Socket
Socket
Sign inDemoInstall

joi

Package Overview
Dependencies
Maintainers
4
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 4.3.0 to 4.3.1

2

lib/alternatives.js

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

Hoek.assert(ref, 'Missing reference');
Hoek.assert(Ref.isRef(ref) || typeof ref === 'string', 'Invalid reference:', ref);
Hoek.assert(options, 'Missing options');

@@ -78,0 +78,0 @@ Hoek.assert(typeof options === 'object', 'Invalid options');

@@ -83,2 +83,7 @@ // Load modules

root.isRef = function (ref) {
return Ref.isRef(ref);
};
root.validate = function (value /*, [schema], [options], callback */) {

@@ -85,0 +90,0 @@

@@ -13,3 +13,2 @@ // Load modules

Hoek.assert(key, 'Missing reference key');
Hoek.assert(typeof key === 'string', 'Invalid reference key:', key);

@@ -16,0 +15,0 @@

{
"name": "joi",
"description": "Object schema validation",
"version": "4.3.0",
"version": "4.3.1",
"repository": "git://github.com/spumko/joi",

@@ -6,0 +6,0 @@ "main": "index",

@@ -663,3 +663,3 @@ <a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a>

#### `object.parrern(regex, schema)`
#### `object.pattern(regex, schema)`

@@ -666,0 +666,0 @@ Specify validation rules for unknown keys matching a pattern where:

@@ -109,2 +109,11 @@ // Load modules

it('throws on invalid ref (not string)', function (done) {
expect(function () {
Joi.alternatives().when(5, { is: 6, then: Joi.number() });
}).to.throw('Invalid reference: 5');
done();
});
it('validates conditional alternatives', function (done) {

@@ -128,6 +137,24 @@

it('validates conditional alternatives (empty key)', function (done) {
var schema = {
a: Joi.alternatives().when('', { is: 5, then: 'x', otherwise: 'y' })
.try('z'),
'': Joi.any()
};
Helper.validate(schema, [
[{ a: 'x', '': 5 }, true],
[{ a: 'x', '': 6 }, false],
[{ a: 'y', '': 5 }, false],
[{ a: 'y', '': 6 }, true],
[{ a: 'z', '': 5 }, true],
[{ a: 'z', '': 6 }, true]
], done);
});
it('validates only then', function (done) {
var schema = {
a: Joi.alternatives().when('b', { is: 5, then: 'x' })
a: Joi.alternatives().when(Joi.ref('b'), { is: 5, then: 'x' })
.try('z'),

@@ -134,0 +161,0 @@ b: Joi.any()

@@ -45,2 +45,23 @@ // Load modules

it('uses ref as a valid value (empty key)', function (done) {
var schema = Joi.object({
a: Joi.ref(''),
'': Joi.any()
});
schema.validate({ a: 5, '': 6 }, function (err, value) {
expect(err).to.exist;
expect(err.message).to.equal('a must be one of ref:');
Helper.validate(schema, [
[{ a: 5 }, false],
[{ '': 5 }, true],
[{ a: 5, '': 5 }, true],
[{ a: '5', '': '5' }, true]
], done);
});
});
it('uses ref with nested keys as a valid value', function (done) {

@@ -331,13 +352,11 @@

describe('#create', function () {
it('describes schema with ref', function (done) {
it('throws when key is missing', function (done) {
var desc = Joi.compile(Joi.ref('a.b')).describe();
expect(Joi.isRef(desc.valids[0])).to.be.true;
done();
});
expect(function () {
describe('#create', function () {
Joi.ref();
}).to.throw('Missing reference key');
done();
});
it('throws when key is missing', function (done) {

@@ -344,0 +363,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