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

joi

Package Overview
Dependencies
Maintainers
3
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.3.1 to 0.3.2

4

lib/index.js

@@ -33,2 +33,6 @@ // Load modules

if (config instanceof Types.Base) {
return validateKeyConfig(config, '', object);
}
var unprocessedObject = Utils.clone(object || {});

@@ -35,0 +39,0 @@ var keys = Object.keys(config || {});

@@ -0,0 +0,0 @@ // Load modules

@@ -64,4 +64,13 @@ // Load modules

internals.ObjectType.prototype.allowOtherKeys = function () {
this._allowOtherKeys = true;
return this;
};
internals.ObjectType.prototype._traverse = function (topObj, topConfig, errors, topKeyPath) {
var self = this;
var traverse = function (obj, config, errors, keyPath) {

@@ -92,3 +101,3 @@

if (keys.length) { // Only error on unknown keys when config specifies a structure
if (self._allowOtherKeys !== true && keys.length) { // Only error on unknown keys when config specifies a structure
Object.keys(unprocessedObject).forEach(function (unprocessedKey) {

@@ -95,0 +104,0 @@

2

package.json
{
"name": "joi",
"description": "Object schema validation",
"version": "0.3.1",
"version": "0.3.2",
"author": "Van Nguyen <the.gol.effect@gmail.com>",

@@ -6,0 +6,0 @@ "contributors": [

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

Specifies allowed types for the array value to exclude. The values of n1, n2, ... are Type Registry constraints (usually of other types).
Specifies allowed types for the array value to exclude. The values of n1, n2, ... are Type Registry constraints (usually of other types).

@@ -336,5 +336,7 @@

*Note: Object has no special methods other than those inherited from BaseType*
##### Object.allowOtherKeys()
Will cause any unknown keys in the object being validated to not cause the object to be invalid.
## Usage

@@ -434,3 +436,3 @@

By default Joi tries to parse and convert object's values into correct type. You might want to disable this behaviour e.g. when you are validating program's internal objects instead of user input.
By default Joi tries to parse and convert object's values into correct type. You might want to disable this behaviour e.g. when you are validating program's internal objects instead of user input.

@@ -437,0 +439,0 @@ To force Joi to not convert object values, use the `skipConversions` option:

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

it('should validate config where the root item is a joi type', function (done) {
expect(Joi.validate(true, T.Boolean().nullOk())).to.be.null;
expect(Joi.validate({ auth: { mode: 'try' } }, T.Object())).to.be.null;
expect(Joi.validate(true, T.Object())).to.not.be.null;
expect(Joi.validate(true, T.String())).to.not.be.null;
expect(Joi.validate('test@test.com', T.String().email())).to.be.null;
done();
});
it('should validate an unknown option', function (done) {

@@ -143,0 +154,0 @@

@@ -53,2 +53,24 @@ // Load modules

it('should prevent extra keys from existing by default', function (done) {
var t = O({ item: Joi.types.String().required() }).required();
verifyBehavior(t, [
[{ item: 'something' }, true],
[{ item: 'something', item2: 'something else' }, false],
['', false]
], done);
});
it('should allow extra keys when using allowOtherKeys', function (done) {
var t = O({ item: Joi.types.String().required() }).allowOtherKeys();
verifyBehavior(t, [
[{ item: 'something' }, true],
[{ item: 'something', item2: 'something else' }, true],
[{ item: 'something', item1: 'something', item2: 'something else' }, true],
[{ item1: 'something', item2: 'something else' }, false],
['', false]
], done);
});
it('should traverse an object and validate all properties in the top level', function (done) {

@@ -55,0 +77,0 @@

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