forked from Arnie97/moerail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyfill.js
31 lines (27 loc) · 814 Bytes
/
polyfill.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
Array.prototype.findAll = function(fn) {
var arr = [];
this.forEach(function(i) {
if (fn(i)) {
arr.push(i);
}
});
return arr;
};
Array.prototype.randomElement = function() {
return this[Math.floor(Math.random() * this.length)];
};
Array.prototype.link = function(i, url) {
url = url.format(this);
var link = '<a href="{0}" target="_blank">{1}</a>';
return (this[i] = link.format([url, this[i]]));
};
String.prototype.format = function(args) {
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'? args[number]: match;
});
};
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(s, position) {
return this.substr(position || 0, s.length) === s;
};
}