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 12.0.0 to 13.0.0

73

lib/index.js

@@ -48,5 +48,5 @@ 'use strict';

root.any = function () {
root.any = function (...args) {
Hoek.assert(arguments.length === 0, 'Joi.any() does not allow arguments.');
Hoek.assert(args.length === 0, 'Joi.any() does not allow arguments.');

@@ -56,11 +56,11 @@ return internals.applyDefaults.call(this, any);

root.alternatives = root.alt = function () {
root.alternatives = root.alt = function (...args) {
const alternatives = internals.applyDefaults.call(this, internals.alternatives);
return arguments.length ? alternatives.try.apply(alternatives, arguments) : alternatives;
return args.length ? alternatives.try.apply(alternatives, args) : alternatives;
};
root.array = function () {
root.array = function (...args) {
Hoek.assert(arguments.length === 0, 'Joi.array() does not allow arguments.');
Hoek.assert(args.length === 0, 'Joi.array() does not allow arguments.');

@@ -70,5 +70,5 @@ return internals.applyDefaults.call(this, internals.array);

root.boolean = root.bool = function () {
root.boolean = root.bool = function (...args) {
Hoek.assert(arguments.length === 0, 'Joi.boolean() does not allow arguments.');
Hoek.assert(args.length === 0, 'Joi.boolean() does not allow arguments.');

@@ -78,5 +78,5 @@ return internals.applyDefaults.call(this, internals.boolean);

root.binary = function () {
root.binary = function (...args) {
Hoek.assert(arguments.length === 0, 'Joi.binary() does not allow arguments.');
Hoek.assert(args.length === 0, 'Joi.binary() does not allow arguments.');

@@ -86,5 +86,5 @@ return internals.applyDefaults.call(this, internals.binary);

root.date = function () {
root.date = function (...args) {
Hoek.assert(arguments.length === 0, 'Joi.date() does not allow arguments.');
Hoek.assert(args.length === 0, 'Joi.date() does not allow arguments.');

@@ -94,5 +94,5 @@ return internals.applyDefaults.call(this, internals.date);

root.func = function () {
root.func = function (...args) {
Hoek.assert(arguments.length === 0, 'Joi.func() does not allow arguments.');
Hoek.assert(args.length === 0, 'Joi.func() does not allow arguments.');

@@ -102,5 +102,5 @@ return internals.applyDefaults.call(this, internals.func);

root.number = function () {
root.number = function (...args) {
Hoek.assert(arguments.length === 0, 'Joi.number() does not allow arguments.');
Hoek.assert(args.length === 0, 'Joi.number() does not allow arguments.');

@@ -110,11 +110,11 @@ return internals.applyDefaults.call(this, internals.number);

root.object = function () {
root.object = function (...args) {
const object = internals.applyDefaults.call(this, internals.object);
return arguments.length ? object.keys.apply(object, arguments) : object;
return args.length ? object.keys(...args) : object;
};
root.string = function () {
root.string = function (...args) {
Hoek.assert(arguments.length === 0, 'Joi.string() does not allow arguments.');
Hoek.assert(args.length === 0, 'Joi.string() does not allow arguments.');

@@ -124,5 +124,5 @@ return internals.applyDefaults.call(this, internals.string);

root.ref = function () {
root.ref = function (...args) {
return Ref.create.apply(null, arguments);
return Ref.create(...args);
};

@@ -135,14 +135,14 @@

root.validate = function (value /*, [schema], [options], callback */) {
root.validate = function (value, ...args /*, [schema], [options], callback */) {
const last = arguments[arguments.length - 1];
const last = args[args.length - 1];
const callback = typeof last === 'function' ? last : null;
const count = arguments.length - (callback ? 1 : 0);
if (count === 1) {
const count = args.length - (callback ? 1 : 0);
if (count === 0) {
return any.validate(value, callback);
}
const options = count === 3 ? arguments[2] : {};
const schema = root.compile(arguments[1]);
const options = count === 2 ? args[1] : {};
const schema = root.compile(args[0]);

@@ -152,5 +152,5 @@ return schema._validateWithOptions(value, options, callback);

root.describe = function () {
root.describe = function (...args) {
const schema = arguments.length ? root.compile(arguments[0]) : any;
const schema = args.length ? root.compile(args[0]) : any;
return schema.describe();

@@ -257,5 +257,5 @@ };

root.extend = function () {
root.extend = function (...args) {
const extensions = Hoek.flatten(Array.prototype.slice.call(arguments));
const extensions = Hoek.flatten(args);
Hoek.assert(extensions.length > 0, 'You need to provide at least one extension');

@@ -351,9 +351,8 @@

type.prototype[rule.name] = function () { // eslint-disable-line no-loop-func
type.prototype[rule.name] = function (...rArgs) { // eslint-disable-line no-loop-func
if (arguments.length > ruleArgs.length) {
if (rArgs.length > ruleArgs.length) {
throw new Error('Unexpected number of arguments');
}
const args = Array.prototype.slice.call(arguments);
let hasRef = false;

@@ -363,4 +362,4 @@ let arg = {};

for (let k = 0; k < ruleArgs.length; ++k) {
arg[ruleArgs[k]] = args[k];
if (!hasRef && Ref.isRef(args[k])) {
arg[ruleArgs[k]] = rArgs[k];
if (!hasRef && Ref.isRef(rArgs[k])) {
hasRef = true;

@@ -367,0 +366,0 @@ }

@@ -70,5 +70,5 @@ 'use strict';

try(/* schemas */) {
try(...schemas) {
const schemas = Hoek.flatten(Array.prototype.slice.call(arguments));
schemas = Hoek.flatten(schemas);
Hoek.assert(schemas.length, 'Cannot add other alternatives without at least one schema');

@@ -75,0 +75,0 @@

@@ -81,5 +81,5 @@ 'use strict';

createError(type, context, state, options, flags) {
createError(type, context, state, options, flags = this._flags) {
return Errors.create(type, context, state, options, flags || this._flags);
return Errors.create(type, context, state, options, flags);
}

@@ -256,6 +256,6 @@

allow() {
allow(...values) {
const obj = this.clone();
const values = Hoek.flatten(Array.prototype.slice.call(arguments));
values = Hoek.flatten(values);
for (let i = 0; i < values.length; ++i) {

@@ -271,5 +271,5 @@ const value = values[i];

valid() {
valid(...values) {
const obj = this.allow.apply(this, arguments);
const obj = this.allow(...values);
obj._flags.allowOnly = true;

@@ -279,8 +279,8 @@ return obj;

invalid(value) {
invalid(...values) {
const obj = this.clone();
const values = Hoek.flatten(Array.prototype.slice.call(arguments));
values = Hoek.flatten(values);
for (let i = 0; i < values.length; ++i) {
value = values[i];
const value = values[i];

@@ -450,5 +450,6 @@ Hoek.assert(value !== undefined, 'Cannot call allow/valid/invalid with undefined');

example(value) {
example(...args) {
Hoek.assert(arguments.length, 'Missing example');
Hoek.assert(args.length === 1, 'Missing example');
const value = args[0];
const result = this._validate(value, null, internals.defaults);

@@ -900,8 +901,4 @@ Hoek.assert(!result.errors, 'Bad example:', result.errors && Errors.process(result.errors, value));

const obj = {};
const obj = Object.assign({}, target);
if (target) {
Object.assign(obj, target);
}
if (source) {

@@ -908,0 +905,0 @@ const sKeys = Object.keys(source);

@@ -331,7 +331,7 @@ 'use strict';

items() {
items(...schemas) {
const obj = this.clone();
Hoek.flatten(Array.prototype.slice.call(arguments)).forEach((type, index) => {
Hoek.flatten(schemas).forEach((type, index) => {

@@ -368,7 +368,7 @@ try {

ordered() {
ordered(...schemas) {
const obj = this.clone();
Hoek.flatten(Array.prototype.slice.call(arguments)).forEach((type, index) => {
Hoek.flatten(schemas).forEach((type, index) => {

@@ -375,0 +375,0 @@ try {

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

truthy() {
truthy(...values) {
const obj = this.clone();
const values = Hoek.flatten(Array.prototype.slice.call(arguments));
values = Hoek.flatten(values);
for (let i = 0; i < values.length; ++i) {

@@ -63,6 +63,6 @@ const value = values[i];

falsy() {
falsy(...values) {
const obj = this.clone();
const values = Hoek.flatten(Array.prototype.slice.call(arguments));
values = Hoek.flatten(values);
for (let i = 0; i < values.length; ++i) {

@@ -69,0 +69,0 @@ const value = values[i];

@@ -109,8 +109,6 @@ 'use strict';

timestamp(type) {
timestamp(type = 'javascript') {
type = type || 'javascript';
const allowed = ['javascript', 'unix'];
Hoek.assert(allowed.indexOf(type) !== -1, '"type" must be one of "' + allowed.join('", "') + '"');
Hoek.assert(allowed.includes(type), '"type" must be one of "' + allowed.join('", "') + '"');

@@ -117,0 +115,0 @@ if (this._flags.timestamp === type) {

@@ -74,5 +74,5 @@ 'use strict';

else {
target = function () {
target = function (...args) {
return value.apply(this, arguments);
return value.apply(this, args);
};

@@ -343,3 +343,3 @@

// Only add the key if we are not going to replace it later
if (children.indexOf(child.key) === -1) {
if (!children.includes(child.key)) {
topo.add(child, { after: child._refs, group: child.key });

@@ -474,41 +474,41 @@ }

xor() {
xor(...peers) {
const peers = Hoek.flatten(Array.prototype.slice.call(arguments));
peers = Hoek.flatten(peers);
return this._dependency('xor', null, peers);
}
or() {
or(...peers) {
const peers = Hoek.flatten(Array.prototype.slice.call(arguments));
peers = Hoek.flatten(peers);
return this._dependency('or', null, peers);
}
and() {
and(...peers) {
const peers = Hoek.flatten(Array.prototype.slice.call(arguments));
peers = Hoek.flatten(peers);
return this._dependency('and', null, peers);
}
nand() {
nand(...peers) {
const peers = Hoek.flatten(Array.prototype.slice.call(arguments));
peers = Hoek.flatten(peers);
return this._dependency('nand', null, peers);
}
requiredKeys(children) {
requiredKeys(...children) {
children = Hoek.flatten(Array.prototype.slice.call(arguments));
children = Hoek.flatten(children);
return this.applyFunctionToChildren(children, 'required');
}
optionalKeys(children) {
optionalKeys(...children) {
children = Hoek.flatten(Array.prototype.slice.call(arguments));
children = Hoek.flatten(children);
return this.applyFunctionToChildren(children, 'optional');
}
forbiddenKeys(children) {
forbiddenKeys(...children) {
children = Hoek.flatten(Array.prototype.slice.call(arguments));
children = Hoek.flatten(children);
return this.applyFunctionToChildren(children, 'forbidden');

@@ -676,7 +676,7 @@ }

type(constructor, name) {
type(constructor, name = constructor.name) {
Hoek.assert(typeof constructor === 'function', 'type must be a constructor function');
const typeData = {
name: name || constructor.name,
name,
ctor: constructor

@@ -683,0 +683,0 @@ };

@@ -211,6 +211,5 @@ 'use strict';

ip(ipOptions) {
ip(ipOptions = {}) {
let regex = internals.ipRegex;
ipOptions = ipOptions || {};
Hoek.assert(typeof ipOptions === 'object', 'options must be an object');

@@ -418,6 +417,4 @@

base64(base64Options) {
base64(base64Options = {}) {
base64Options = base64Options || {};
// Validation.

@@ -466,5 +463,4 @@ Hoek.assert(typeof base64Options === 'object', 'base64 options must be an object');

normalize(form) {
normalize(form = 'NFC') {
form = form || 'NFC';
Hoek.assert(Hoek.contain(internals.normalizationForms, form), 'normalization form must be one of ' + internals.normalizationForms.join(', '));

@@ -471,0 +467,0 @@

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

@@ -14,8 +14,8 @@ "repository": "git://github.com/hapijs/joi",

"engines": {
"node": ">=4.0.0"
"node": ">=8.3.0"
},
"dependencies": {
"hoek": "4.x.x",
"hoek": "5.x.x",
"isemail": "3.x.x",
"topo": "2.x.x"
"topo": "3.x.x"
},

@@ -22,0 +22,0 @@ "devDependencies": {

@@ -29,3 +29,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/v12.0.0/API.md).
See the detailed [API Reference](https://github.com/hapijs/joi/blob/v13.0.0/API.md).

@@ -32,0 +32,0 @@ # Example

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