-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.advanced.js
More file actions
executable file
·58 lines (50 loc) · 1.88 KB
/
javascript.advanced.js
File metadata and controls
executable file
·58 lines (50 loc) · 1.88 KB
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
50
51
52
53
54
55
56
57
58
/**
* Advanced functions for JS.
* Copyright (c) 2014 Evgeniy Blinov (https://evgeniyblinov.ru)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @link https://github.com/EvgeniyBlinov/JS for the canonical source repository
* @author Evgeniy Blinov <evgeniy_blinov@mail.ru>
* @copyright Copyright (c) 2014 Evgeniy Blinov
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
(function(){
'use strict';
if (!String.prototype.trim) {
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};
}
if (!String.prototype.ltrim) {
String.prototype.ltrim=function(){return this.replace(/^\s+/,'');};
}
if (!String.prototype.rtrim) {
String.prototype.rtrim=function(){return this.replace(/\s+$/,'');};
}
if (!String.prototype.fulltrim) {
String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');};
}
if (!String.prototype.toDOM) {
String.prototype.toDOM = function(){
var d = document,
i,
a = d.createElement("div"),
b = d.createDocumentFragment();
a.innerHTML = this;
while ( i = a.firstChild ) b.appendChild(i);
return b;
};
}
this.getType = function( object ) {
return Object.prototype.toString.call( object ).slice(8, -1);
};
this.randomString = function (len, charSet) {
charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var randomString = '';
for (var i = 0; i < len; i++) {
var randomPoz = Math.floor(Math.random() * charSet.length);
randomString += charSet.substring(randomPoz,randomPoz+1);
}
return randomString;
};
}).call(this);