-
Notifications
You must be signed in to change notification settings - Fork 10
/
validations.js
33 lines (32 loc) · 1.04 KB
/
validations.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
var validations = (function() {
"use strict";
return {
validateArgsLength: function(argsLength, argsArray) {
if (argsArray.length != argsLength) {
throw {
name: "ArgumentsException",
message: "The arguments length is incorrect."
};
}
},
validateArgsTypes: function(argsArray, argumentValidatorArray) {
_.each(argsArray, function(argument, index) {
if (!argumentValidatorArray[index](argument)) {
throw {
name: "ArgumentsException",
message: "One of the arguments does not have the expected type."
};
}
});
},
validateContactArgs: function(argsArray) {
this.validateArgsTypes(
argsArray, [_.isNumber, _.isString, _.isString, _.isString, _.isString, _.isString, _.isString]);
},
validateClientArgs: function(argsArray) {
this.validateContactArgs(_.first(argsArray, 7));
this.validateArgsTypes(
_.rest(argsArray, 7), [_.isDate, _.isString, _.isNumber, _.isString]);
}
};
}());