/
utils.js
39 lines (32 loc) · 896 Bytes
/
utils.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
this.trim = function(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g, '');
};
this.ltrim = function(stringToTrim) {
return stringToTrim.replace(/^\s+/, '');
};
this.rtrim = function(stringToTrim) {
return stringToTrim.replace(/\s+$/, '');
};
this.urlRE = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([^\s]*(\?\S+)?)?)?/g,
this.escape = function(inputHtml) {
inputHtml = inputHtml.toString();
return inputHtml.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>');
};
this.zeroPad = function(digits, n) {
n = n.toString();
while (n.length < digits) {
n = '0' + n;
}
return n;
};
this.timeString = function(date) {
var minutes = date.getMinutes().toString();
var hours = date.getHours().toString();
return this.zeroPad(2, hours) + ':' + this.zeroPad(2, minutes);
};
this.isBlank = function(text) {
var blank = /^\s*$/;
return (text.match(blank) !== null);
};