aboutsummaryrefslogtreecommitdiff
path: root/node_modules/joi/lib/cast.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/joi/lib/cast.js')
-rw-r--r--node_modules/joi/lib/cast.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/node_modules/joi/lib/cast.js b/node_modules/joi/lib/cast.js
new file mode 100644
index 00000000..19c4a677
--- /dev/null
+++ b/node_modules/joi/lib/cast.js
@@ -0,0 +1,64 @@
+'use strict';
+
+// Load modules
+
+const Hoek = require('hoek');
+const Ref = require('./ref');
+
+// Type modules are delay-loaded to prevent circular dependencies
+
+
+// Declare internals
+
+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);
+};