forked from asalga/Horadrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.js
60 lines (49 loc) · 984 Bytes
/
Utils.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
50
51
52
53
54
55
56
57
58
59
/*
* JS Utilities interface
*/
var Utils = {
/*
Used to identify tokens.
*/
nextID: function(){
var inc =
(function(){
var id = -1;
return function(){
id++;
}
})();
return inc();
},
/*
*/
charCodeAt: function(ch){
return ch.charCodeAt(0);
},
/*
*
*/
getRandomInt: function(minVal, maxVal){
var scale = Math.random();
return minVal + Math.floor(scale * (maxVal - minVal + 1));
},
Lerp: function(a, b, p){
return a * (1-p) + (b * p);
},
floatToInt:function(f){
return Math.floor(f);
},
/*
*/
prependStringWithString: function(baseString, prefix, newStrLength){
var zerosToAdd, i;
if(newStrLength <= baseString.length()){
return baseString;
}
zerosToAdd = newStrLength - baseString.length();
for(i = 0; i < zerosToAdd; i++){
baseString = prefix + baseString;
}
return baseString;
}
}