-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.js
55 lines (53 loc) · 1.42 KB
/
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
function formatVal(val, format) {
if( !format ) return val;
switch ( format ) {
case "sign" :
return val > 0 ? "+" + val : val ;
break;
case "aztext" :
return val.toLowerCase().replace(/[^a-z]/g, "");
break;
case "azspaceminustext" : //return lowercased string with anything beside a-z, space and minus excluded
return val.toLowerCase().replace(/[^a-z(\-)(\ )]/g, "");
break;
case "d2pr" : // "percents" 0.54321 > 54.32%
return Math.round(val*10000)/100 + "%";
break;
case "d2pp" : // "plain percents" 0.54321 > 54.3
return Math.round(val*1000)/10;
break;
case "d2sd" :
return Math.round(val*100)/100;
break;
case "d2fd" :
var res = Math.round(val*10)/10;
if( res-Math.round(res) === 0) res += ".0";
return res + " ";
break;
case "h2hm" :
var hrs = (val/60 < 10 ? "0" : "") + Math.floor(val/60);
var mns = (val%60 < 10 ? "0" : "") + Math.round(val%60);
return hrs + ":" + mns;
break;
case "wikiurl" :
return encodeURIComponent(val.replace(/\ +/g, "_") );
break;
default :
return val;
}
}
function azContains(a, b){
if ( arrayIncludes(strictMatch, b) ) {
return (formatVal(a, "aztext") == formatVal(b, "aztext"));
} else {
return formatVal(a, "aztext").indexOf( formatVal(b, "aztext") ) !== -1;
}
}
function arrayIncludes(array, item) {
for (var i = 0; i < array.length; i++) {
if (array[i] == item) {
return true;
}
}
return false;
}