forked from beginner-corp/validate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathone-of.js
46 lines (40 loc) · 927 Bytes
/
one-of.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// wip experimental extension to allow validation of N named schemas
// passes if any one schema works
/**
* var validate = require('@smallwins/validate/one-of')
*
* function valid(params) {
* var schema = {
* rpc: {
* 'query.x': {required:true, type:String}
* },
* www: {
* 'query.y': {required:true, type:String}
* }
* }
* return validate(params, schema)
* }
*
*/
var validate = require('./')
module.exports = function oneOf(params, schema, callback) {
// schema is three levels
// values are all objects
// the final layer keys can only be one of required, type, min and max
var schemas = Object.keys(schema)
for (var i = 0; i < schemas.length; i++) {
var tryna = validate(params, schemas[i])
if (tryna) {
// continue loop
}
else {
// break loop
failed = false
break
}
}
if (failed) {
}
else {
}
}