-
Notifications
You must be signed in to change notification settings - Fork 4
/
common.js
32 lines (31 loc) · 1.08 KB
/
common.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
String.prototype.contains = function (contains) { return this.indexOf(contains) > -1; };
Array.prototype.contains = function (contains) { return this.indexOf(contains) > -1; };
String.prototype.isEmptyOrWhitespace = function () { return this.match(/^\s*$/); };
String.prototype.pad = function (size) {
var s = String(this);
if (typeof (size) !== "number") { size = 2; }
while (s.length < size) { s = "0" + s; }
return s;
};
Number.prototype.pad = String.prototype.pad;
if (!String.prototype.format) {
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
if (!String.prototype.template) {
String.prototype.template = function (obj) {
return this.replace(/{{\$(.+?)}}/g, function (match, field) {
return typeof obj[field] != 'undefined'
? obj[field]
: match
;
});
};
}