-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.logging.js
More file actions
48 lines (48 loc) · 1.36 KB
/
jquery.logging.js
File metadata and controls
48 lines (48 loc) · 1.36 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
(function($) {
$.fn.log = function(val) {
this.getType = function(val) {
try {
if (typeof val === 'undefined') return 'undefined';
if (typeof val === 'object' && !val) return 'null';
return ({}).toString.call(val).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
} catch (ex) {
return 'undefined';
}
};
this.isConsole = function() {
return (this.console !== undefined && this.console !== null && this.console.log !== undefined);
};
this.isString = function(val) {
var type = this.getType(val);
return (type === 'string' || type === 'number' || type === 'boolean');
};
this.getConsolVal = function(val) {
if (val !== undefined && val !== null && this.getType(val)) {
if (this.isString(val)) {
return val;
} else if (this.getType(val) === 'object') {
return val;
} else {
return this.getType(val);
}
}
return undefined;
};
this.getTextVal = function(val) {
if (val !== undefined && val !== null && this.getType(val)) {
if (this.isString(val)) {
return val;
}
}
return undefined;
};
if (this.isConsole()) {
var toLog = this.getConsolVal(val);
if (toLog !== undefined && toLog !== null && toLog !== 'undefined' && toLog !== 'null') {
console.log(toLog);
} else {
console.log('Value in undefined');
}
}
};
})(jQuery);