-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.js
120 lines (107 loc) · 2.32 KB
/
module.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* jshint esnext:true */
/**
* Checks if the variable is null or undefined
* @public
* @type {Function}
* @param {Mixed} v The variable to test.
* @return {Boolean}
*/
export function isNullOrUndefined(v) {
return typeof v === 'undefined' || v === null;
}
/**
* Checks if the variable is a string.
* @public
* @type {Function}
* @param {String} s The variable to test.
* @return {Boolean}
*/
export function isStr(s) {
return typeof s === 'string';
}
/**
* Checks if the variable is an array.
* @public
* @type {Function}
* @param {Array} a The variable to test.
* @return {Boolean}
*/
export function isArr(a) {
return !isNullOrUndefined(a) && Object.prototype.toString.call(a) === '[object Array]';
}
/**
* Checks if the variable is a number.
* @public
* @type {Function}
* @param {Number} n The variable to test.
* @return {Boolean}
*/
export function isNum(n) {
return typeof n === 'number' && !isNaN(n);
}
/**
* Checks if the variable is an object.
* @public
* @type {Function}
* @param {Object} o The variable to test.
* @return {Boolean}
*/
export function isObj(o) {
return !isArr(o) && typeof obj === 'object';
}
/**
* Checks if the variable is a function.
* @public
* @type {Function}
* @param {Function} f The variable to test.
* @return {Boolean}
*/
export function isFnc(f) {
return typeof f === 'function';
}
/**
* Checks if the variable is a string and that it's not empty.
* @public
* @type {Function}
* @param {String} s The variable to test.
* @return {Boolean}
*/
export function validStr(s) {
return isStr(s) && !!s.length;
}
/**
* Checks if the variable is an array and that it's not empty. Only goes one level deep.
* @public
* @type {Function}
* @param {Array} a The variable to test.
* @return {Boolean}
*/
export function validArr(a) {
return isArr(a) && !!a.length;
}
/**
* Checks if the variable is a number and that is greater than 0.
* @public
* @type {Function}
* @param {Number} n The variable to test.
* @return {Boolean}
*/
export function validNum(n) {
return isNum(n) && n > 0;
}
/**
* Checks if the variable is an object and that it's not an empty object.
* @public
* @type {Function}
* @param {Object} o The variable to test.
* @return {Boolean}
*/
export function validObj(o) {
var i;
if (isObj(o)) {
for (i in o) {
return true;
}
}
return false;
}