1 | |
---|
2 | // ----------------------------------------------------------------------------- |
---|
3 | // NanoAjax function library |
---|
4 | // |
---|
5 | |
---|
6 | String.prototype.repeat = function( number ) |
---|
7 | { |
---|
8 | return new Array( number + 1 ).join( this ); |
---|
9 | }; |
---|
10 | |
---|
11 | String.prototype.ucFirst = function () |
---|
12 | { |
---|
13 | return this.substr(0,1).toUpperCase() + this.substr(1,this.length); |
---|
14 | }; |
---|
15 | |
---|
16 | String.prototype.nl2br = function () |
---|
17 | { |
---|
18 | return this.replace(/\n/g,'<br/>'); |
---|
19 | }; |
---|
20 | |
---|
21 | String.prototype.ltrim = function () |
---|
22 | { |
---|
23 | return (this.replace(/^\s+/,"")); |
---|
24 | }; |
---|
25 | |
---|
26 | String.prototype.rtrim = function () |
---|
27 | { |
---|
28 | return (this.replace(/\s+$/,"")); |
---|
29 | }; |
---|
30 | |
---|
31 | //combines "leftTrim" and "rightTrim"; |
---|
32 | String.prototype.trim = function () |
---|
33 | { |
---|
34 | return (this.replace(/\s+$/,"").replace(/^\s+/,"")); |
---|
35 | }; |
---|
36 | |
---|
37 | //removes n spaces in string to 1 (one) space |
---|
38 | String.prototype.superTrim = function () |
---|
39 | { |
---|
40 | return(this.replace(/\s+/g," ").replace(/\s+$/,"").replace(/^\s+/,"")); //" |
---|
41 | }; |
---|
42 | |
---|
43 | // removes all spaces from string |
---|
44 | String.prototype.removeWhiteSpaces = function () |
---|
45 | { |
---|
46 | return (this.replace(/\s+/g,"")); |
---|
47 | }; |
---|
48 | |
---|
49 | // fills string with given char and count |
---|
50 | String.prototype.fillChar = function ( fill_char, fill_count, fill_position ) |
---|
51 | { |
---|
52 | var fill_position = (fill_position) ? fill_position : 'left'; |
---|
53 | var str_len = this.length; |
---|
54 | var tmp_str = this; |
---|
55 | |
---|
56 | if(str_len < fill_count) |
---|
57 | { |
---|
58 | while(str_len < fill_count) |
---|
59 | { |
---|
60 | tmp_str = ( 'left' == fill_position ) |
---|
61 | ? (fill_char + tmp_str) |
---|
62 | : (tmp_str + fill_char); |
---|
63 | |
---|
64 | ++str_len; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | return tmp_str; |
---|
69 | }; |
---|
70 | |
---|
71 | // like PHP' in_array |
---|
72 | Array.prototype.contains = function( element ) |
---|
73 | { |
---|
74 | for ( var idx = 0; idx < this.length; idx++ ) |
---|
75 | { |
---|
76 | if( element == this[idx] ) |
---|
77 | { |
---|
78 | return true; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | return false; |
---|
83 | }; |
---|