Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
internals.Plugin.prototype.select = function (/* labels */) {
var labels = [];
for (var i = 0, il = arguments.length; i < il; ++i) {
labels.push(arguments[i]);
}
labels = Hoek.flatten(labels);
return this._select(labels);
};
internals.Object.prototype.xor = function () {
var peers = Hoek.flatten(Array.prototype.slice.call(arguments));
return this._dependency('xor', null, peers);
};
internals.Array.prototype.items = function () {
var obj = this.clone();
Hoek.flatten(Array.prototype.slice.call(arguments)).forEach(function (type) {
type = Cast.schema(type);
obj._inner.items.push(type);
if (type._flags.presence === 'required') {
obj._inner.requireds.push(type);
}
else if (type._flags.presence === 'forbidden') {
obj._inner.exclusions.push(type.optional());
}
else {
obj._inner.inclusions.push(type);
}
});
return obj;
root.extend = function (...args) {
const extensions = Hoek.flatten(args);
Hoek.assert(extensions.length > 0, 'You need to provide at least one extension');
this.assert(extensions, root.extensionsSchema);
const joi = Object.create(this.any());
Object.assign(joi, this);
joi._currentJoi = joi;
joi._binds = new Set(joi._binds);
for (let i = 0; i < extensions.length; ++i) {
let extension = extensions[i];
if (typeof extension === 'function') {
extension = extension(joi);
}
and() {
const peers = Hoek.flatten(Array.prototype.slice.call(arguments));
return this._dependency('and', null, peers);
}
internals.Any.prototype._allow = function () {
var values = Hoek.flatten(Array.prototype.slice.call(arguments));
for (var i = 0, il = values.length; i < il; ++i) {
var value = values[i];
this._invalids.remove(value);
this._valids.add(value, this._refs);
}
};
internals.Any.prototype._allow = function () {
var values = Hoek.flatten(Array.prototype.slice.call(arguments));
for (var i = 0, il = values.length; i < il; ++i) {
var value = values[i];
Hoek.assert(value !== undefined, 'Cannot call allow/valid/invalid with undefined');
this._invalids.remove(value);
this._valids.add(value, this._refs);
}
};
internals.Object.prototype.requiredKeys = function (children) {
children = Hoek.flatten(Array.prototype.slice.call(arguments));
return this.applyFunctionToChildren(children, 'required');
};
root.extend = function (...args) {
const extensions = Hoek.flatten(args);
Hoek.assert(extensions.length > 0, 'You need to provide at least one extension');
this.assert(extensions, root.extensionsSchema);
const joi = Object.create(this.any());
Object.assign(joi, this);
for (let i = 0; i < extensions.length; ++i) {
let extension = extensions[i];
if (typeof extension === 'function') {
extension = extension(joi);
}
this.assert(extension, root.extensionSchema);
allow(...values) {
const obj = this.clone();
values = Hoek.flatten(values);
for (let i = 0; i < values.length; ++i) {
const value = values[i];
Hoek.assert(value !== undefined, 'Cannot call allow/valid/invalid with undefined');
obj._invalids.remove(value);
obj._valids.add(value, obj._refs);
}
return obj;
}