-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototypes.js
49 lines (45 loc) · 986 Bytes
/
prototypes.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
40
41
42
43
44
45
46
47
48
49
if (!Array.prototype.pushUnique)
{
Array.prototype.pushUnique = function (object)
{
var scan = 0;
this.forEach(function (entry)
{
if (entry == object)
scan++;
});
if (scan == 0)
{
this.push(object);
return true;
}
else
return false;
};
}
if (!String.prototype.insert)
{
String.prototype.insert = function ()
{
var string = this;
for (var i = 0; i < arguments.length; i++)
{
var target = "{" + i + "}";
string = string.replace(target, arguments[i].toString());
}
return string;
}
}
if (!String.prototype.nl2br)
{
/**
* @param [is_xhtml] {boolean}
* @returns {string}
*/
String.prototype.nl2br = function(is_xhtml)
{
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (this + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
//return this.replace("\n", "<br>").replace("\\n", "<br>");
}
}