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 13.1.2 to 13.2.0

lib/types/any/settings.js

44

lib/index.js

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

const Ref = require('./ref');
const Settings = require('./types/any/settings');

@@ -195,21 +196,27 @@

Hoek.assert(schema && schema instanceof Any, 'you must provide a joi schema');
Hoek.assert(typeof path === 'string', 'path must be a string');
Hoek.assert(Array.isArray(path) || typeof path === 'string', 'path must be a string or an array of strings');
if (path === '') {
return schema;
}
const reach = (sourceSchema, schemaPath) => {
const parts = path.split('.');
const children = schema._inner.children;
if (!children) {
return;
}
if (!schemaPath.length) {
return sourceSchema;
}
const key = parts[0];
for (let i = 0; i < children.length; ++i) {
const child = children[i];
if (child.key === key) {
return this.reach(child.schema, path.substr(key.length + 1));
const children = sourceSchema._inner.children;
if (!children) {
return;
}
}
const key = schemaPath.shift();
for (let i = 0; i < children.length; ++i) {
const child = children[i];
if (child.key === key) {
return reach(child.schema, schemaPath);
}
}
};
const schemaPath = typeof path === 'string' ? path.split('.') : path.slice();
return reach(schema, schemaPath);
};

@@ -281,5 +288,6 @@

if (extension.language) {
this._settings = this._settings || { language: {} };
this._settings.language = Hoek.applyToDefaults(this._settings.language, {
[extension.name]: extension.language
this._settings = Settings.concat(this._settings, {
language: {
[extension.name]: extension.language
}
});

@@ -286,0 +294,0 @@ }

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

ref: 'references "{{ref}}" which is not a number',
multiple: 'must be a multiple of {{multiple}}'
multiple: 'must be a multiple of {{multiple}}',
port: 'must be a valid port'
},

@@ -124,0 +125,0 @@ string: {

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

const Hoek = require('hoek');
const Settings = require('./settings');
const Ref = require('../../ref');

@@ -108,6 +109,6 @@ const Errors = require('../../errors');

obj._type = this._type;
obj._settings = internals.concatSettings(this._settings);
obj._settings = this._settings;
obj._baseType = this._baseType;
obj._valids = Hoek.clone(this._valids);
obj._invalids = Hoek.clone(this._invalids);
obj._valids = this._valids.slice();
obj._invalids = this._invalids.slice();
obj._tests = this._tests.slice();

@@ -155,3 +156,3 @@ obj._refs = this._refs.slice();

obj._settings = obj._settings ? internals.concatSettings(obj._settings, schema._settings) : schema._settings;
obj._settings = obj._settings ? Settings.concat(obj._settings, schema._settings) : schema._settings;
obj._valids.merge(schema._valids, schema._invalids);

@@ -224,3 +225,3 @@ obj._invalids.merge(schema._invalids, schema._valids);

const obj = this.clone();
obj._settings = internals.concatSettings(obj._settings, options);
obj._settings = Settings.concat(obj._settings, options);
return obj;

@@ -232,4 +233,5 @@ }

const obj = this.clone();
obj._settings = obj._settings || {};
obj._settings.convert = isStrict === undefined ? false : !isStrict;
const convert = isStrict === undefined ? false : !isStrict;
obj._settings = Settings.concat(obj._settings, { convert });
return obj;

@@ -488,3 +490,3 @@ }

if (this._settings) {
options = internals.concatSettings(options, this._settings);
options = Settings.concat(options, this._settings);
}

@@ -672,3 +674,3 @@

const settings = internals.concatSettings(internals.defaults, options);
const settings = Settings.concat(internals.defaults, options);
const result = this._validate(value, null, settings);

@@ -890,31 +892,1 @@ const errors = Errors.process(result.errors, value);

};
internals.concatSettings = function (target, source) {
// Used to avoid cloning context
if (!target &&
!source) {
return null;
}
const obj = Object.assign({}, target);
if (source) {
const sKeys = Object.keys(source);
for (let i = 0; i < sKeys.length; ++i) {
const key = sKeys[i];
if (key !== 'language' ||
!obj.hasOwnProperty(key)) {
obj[key] = source[key];
}
else {
obj[key] = Hoek.applyToDefaults(obj[key], source[key]);
}
}
}
return obj;
};

@@ -498,6 +498,6 @@ 'use strict';

const found = {
string: {},
number: {},
undefined: {},
boolean: {},
string: Object.create(null),
number: Object.create(null),
undefined: Object.create(null),
boolean: Object.create(null),
object: new Map(),

@@ -504,0 +504,0 @@ function: new Map(),

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

try {
result.value = new Buffer(value, this._flags.encoding);
result.value = Buffer.from(value, this._flags.encoding);
}

@@ -35,0 +35,0 @@ catch (e) {

@@ -131,2 +131,14 @@ 'use strict';

port() {
return this._test('port', undefined, function (value, state, options) {
if (!Number.isSafeInteger(value) || value < 0 || value > 65535) {
return this.createError('number.port', { value }, state, options);
}
return value;
});
}
};

@@ -133,0 +145,0 @@

@@ -369,2 +369,11 @@ 'use strict';

append(schema) {
// Skip any changes
if (schema === null || schema === undefined || Object.keys(schema).length === 0) {
return this;
}
return this.keys(schema);
}
unknown(allow) {

@@ -371,0 +380,0 @@

{
"name": "joi",
"description": "Object schema validation",
"version": "13.1.2",
"version": "13.2.0",
"homepage": "https://github.com/hapijs/joi",

@@ -6,0 +6,0 @@ "repository": "git://github.com/hapijs/joi",

@@ -19,3 +19,3 @@ ![joi Logo](https://raw.github.com/hapijs/joi/master/images/joi.png)

# API
See the detailed [API Reference](https://github.com/hapijs/joi/blob/v13.1.2/API.md).
See the detailed [API Reference](https://github.com/hapijs/joi/blob/v13.2.0/API.md).

@@ -123,1 +123,7 @@ # Example

Joi doesn't directly support browsers, but you could use [joi-browser](https://github.com/jeffbski/joi-browser) for an ES5 build of Joi that works in browsers, or as a source of inspiration for your own builds.
## Acknowledgements
This project is kindly sponsored by:
[![nearForm logo](https://www.nearform.com/img/nearform-logotype.svg)](https://nearform.com)

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