-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathobject.js
34 lines (29 loc) · 819 Bytes
/
object.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
module.exports = function() {
/**
* Validates an object.
*
* @param cb The callback function.
*/
this.main.object = function object(cb) {
var expected
, additional;
if(this.validates()) {
this.required();
this.type();
// nested deep properties
if(this.rule.additional === false) {
// NOTE: Object.keys() will throw if you declare `additional`
// NOTE: for the `object` type but do not declare nested `fields` object
expected = Object.keys(this.rule.fields);
additional = this.diff(
expected, Object.keys(this.value));
if(additional) {
this.raise(
this.reasons.additional,
this.messages.additional, additional.join(', '), this.field);
}
}
}
cb();
}
}