-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanse.js
More file actions
41 lines (32 loc) · 830 Bytes
/
cleanse.js
File metadata and controls
41 lines (32 loc) · 830 Bytes
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
module.exports = cleanse
var Hash = require("./hash")
var List = require("./list")
var Type = require("./type")
var builtins = [
[String, Type("string")]
, [Boolean, Type("boolean")]
, [Object, Type("object")]
, [Number, Type("number")]
]
function cleanse(validator) {
if (Array.isArray(validator)) {
return List(validator[0])
} else if (typeof validator === "object") {
return Hash(validator)
}
for (var i = 0; i < builtins.length; i++) {
var tuple = builtins[i]
if (tuple[0] === validator) {
return tuple[1]
}
}
if (typeof validator === "function") {
return validator
}
return equal
function equal(x) {
if (x !== validator) {
return x + " is not equal to " + validator
}
}
}