]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/jslib.js
Reorganise.
[irc/quakenet/qwebirc.git] / js / jslib.js
1 Array.prototype.indexFromEnd = function(d) {
2 var p = this;
3
4 if(d < 0)
5 return p[p.length + d];
6
7 return p[d];
8 }
9
10 /* how horribly inefficient */
11 String.prototype.replaceAll = function(f, t) {
12 var i = this.indexOf(f);
13 var c = this;
14
15 while(i > -1) {
16 c = c.replace(f, t);
17 i = c.indexOf(f);
18 }
19 return c;
20 }
21
22 /* how horribly inefficient (again) */
23 String.prototype.splitMax = function(by, max) {
24 var items = this.split(by);
25 var newitems = items.slice(0, max-1);
26
27 if(items.length >= max)
28 newitems.push(items.slice(max-1).join(by));
29
30 return newitems;
31 }