-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathSNValidator.js
More file actions
53 lines (53 loc) · 1.89 KB
/
SNValidator.js
File metadata and controls
53 lines (53 loc) · 1.89 KB
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
47
48
49
50
51
52
53
var SNValidator = Class.create();
SNValidator.prototype = {
/**
* checkValidStringArgument Validates that an argument is, in fact, a string
* @param {string} string A string to test
* @return {boolean} true if an object
*/
checkValidStringArgument: function(string) {
return typeof string === 'string';
},
/**
* checkValidObjectArgument Validates that an argument is, in fact, an object
* @param {Object} object An object to test
* @return {Boolean} true if an object
*/
checkValidObjectArgument: function(object) {
return typeof object === 'object';
},
/**
* checkValidNumberArgumentLoose Validates than an argument is, in fact, a valid number, but uses == instead of ===
* @param {number} number A number to test
* @return {boolean} true if the value is a number
*/
checkValidNumberArgumentLoose: function(number) {
return Number(number) == 'number' && !isNaN(Number(number));
},
/**
* checkValidNumberArgumentStric Validates than an argument is, in fact, a valid number, uses ===
* @param {number} number A number to test
* @return {boolean} true if the value is a number
*/
checkValidNumberArgumentStrict: function(number) {
return typeof number === 'number' && !isNaN(number);
},
/**
* checkValidSysIDArgument Validates that an argument is, in fact, a sys_id
* @param {string} sys_id A string to test
* @return {Boolean} true if a sys_id
*/
checkValidSysIDArgument: function(sys_id) {
this.checkValidStringArgument(sys_id);
return sys_id.match(/^[0-9a-f]{32}$/);
},
/**
* checkValidCallbackArgument Validates that an argument is, in fact, a function to callback
* @param {Function} callback A function to test
* @return {boolean} true if a valid function (or object)
*/
checkValidCallbackArgument: function(callback) {
return typeof callback === 'function';
},
type: 'SNValidator'
};