-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathhelper.js
31 lines (28 loc) · 991 Bytes
/
helper.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
class Helper {
static isPresent(variable) {
return typeof(variable) !== 'undefined' && variable !== null && variable !== '';
}
static now() {
return 1 * new Date;
}
static guid() {
return Config.version + '-xxxxxxxx-'.replace(/[x]/g, function(c) {
var r = Math.random()*36|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(36);
}) + (1 * new Date()).toString(36);
}
// reduces all optional data down to a string
static optionalData(data) {
if (Helper.isPresent(data) === false) {
return '';
} else if (typeof data === 'object') {
// runs Helper.optionalData again to reduce to string in case something else was returned
return Helper.optionalData(JSON.stringify(data));
} else if (typeof data === 'function') {
// runs the function and calls Helper.optionalData again to reduce further if it isn't a string
return Helper.optionalData(data());
} else {
return String(data);
}
}
}