forked from manicken/manicken.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjectExtensions.js
47 lines (41 loc) · 1.59 KB
/
objectExtensions.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
Array.prototype.pushArray = function (other_array) {
/* You should include a test to check whether other_array really is an array */
//console.warn(typeof other_array);
other_array.forEach(function(v) {this.push(v)}, this);
}
Array.prototype.addToBeginningOfEach = function (str) {
for (var i=0;i<this.length;i++)
this[i] = str + this[i];
}
String.prototype.replaceAllVal = function (oldVal, newVal) {
return this.split(oldVal).join(newVal);
}
String.prototype.EqualToAny = function (...strings) {
for (var i = 0; i < strings.length; i++)
if (this == strings[i]) return true;
return false;
}
String.prototype.setCharAt = function(index, chr) {
return this.substring(0, index) + chr + this.substring(index + chr.length);
}
function isDef(object) { return object != undefined;}
function isUDef(object) { return object == undefined;}
function isValidIdentifierName(str)
{
// If first character is invalid
if (!((str[0] >= 'a' && str[0] <= 'z')
|| (str[0]>= 'A' && str[0] <= 'Z')
|| str[0] == '_'))
return false;
// Traverse the string for the rest of the characters
for (let i = 1; i < str.length; i++)
{
if (!((str[i] >= 'a' && str[i] <= 'z')
|| (str[i] >= 'A' && str[i] <= 'Z')
|| (str[i] >= '0' && str[i] <= '9')
|| str[i] == '_'))
return false;
}
// String is a valid identifier
return true;
}