mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 17:35:16 +00:00
60 lines
1.1 KiB
JavaScript
60 lines
1.1 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
const Hoek = require('@hapi/hoek');
|
||
|
|
||
|
const Ref = require('./ref');
|
||
|
|
||
|
|
||
|
const internals = {};
|
||
|
|
||
|
|
||
|
exports.schema = function (Joi, config) {
|
||
|
|
||
|
if (config !== undefined && config !== null && typeof config === 'object') {
|
||
|
|
||
|
if (config.isJoi) {
|
||
|
return config;
|
||
|
}
|
||
|
|
||
|
if (Array.isArray(config)) {
|
||
|
return Joi.alternatives().try(config);
|
||
|
}
|
||
|
|
||
|
if (config instanceof RegExp) {
|
||
|
return Joi.string().regex(config);
|
||
|
}
|
||
|
|
||
|
if (config instanceof Date) {
|
||
|
return Joi.date().valid(config);
|
||
|
}
|
||
|
|
||
|
return Joi.object().keys(config);
|
||
|
}
|
||
|
|
||
|
if (typeof config === 'string') {
|
||
|
return Joi.string().valid(config);
|
||
|
}
|
||
|
|
||
|
if (typeof config === 'number') {
|
||
|
return Joi.number().valid(config);
|
||
|
}
|
||
|
|
||
|
if (typeof config === 'boolean') {
|
||
|
return Joi.boolean().valid(config);
|
||
|
}
|
||
|
|
||
|
if (Ref.isRef(config)) {
|
||
|
return Joi.valid(config);
|
||
|
}
|
||
|
|
||
|
Hoek.assert(config === null, 'Invalid schema content:', config);
|
||
|
|
||
|
return Joi.valid(null);
|
||
|
};
|
||
|
|
||
|
|
||
|
exports.ref = function (id) {
|
||
|
|
||
|
return Ref.isRef(id) ? id : Ref.create(id);
|
||
|
};
|