Repository navigation
Expand file tree
/
Copy pathUtil.js
More file actions
90 lines (71 loc) · 2.25 KB
/
Copy pathUtil.js
File metadata and controls
90 lines (71 loc) · 2.25 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
window.Util = class Util {
static numberWithCommas (x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
static countryCodeEmoji (code) {
let OFFSET = 127397;
let cc = code.toUpperCase();
function _toConsumableArray(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
arr2[i] = arr[i];
}
return arr2;
} else {
return Array.from(arr);
}
}
return /^[A-Z]{2}$/.test(cc) ? String.fromCodePoint.apply(String, _toConsumableArray([].concat(_toConsumableArray(cc)).map(function (c) {
return c.charCodeAt() + OFFSET;
}))) : null;
}
static isUK (country) {
return country.name == "United Kingdom";
}
static higherSignatureCount(firstEl, secondEl) {
if (firstEl.signature_count > secondEl.signature_count) {
return -1;
} else {
return 1;
}
return 0;
}
static higherPercentSigned(firstEl, secondEl) {
let percentF = Math.floor(parseInt(firstEl.signature_count) / parseInt(window.onsData[firstEl.ons_code].population) * 100000) / 1000;
let percentS = Math.floor(parseInt(secondEl.signature_count) / parseInt(window.onsData[secondEl.ons_code].population) * 100000) / 1000;
return percentF > percentS ? -1 : 1;
}
static shortenPartyName(party) {
switch (party) {
case "Scottish National Party":
return "SNP";
case "Democratic Unionist Party":
return "DUP";
case "The Independent Group for Change":
return "TIG";
case "Liberal Democrat":
return "Lib Dem";
case "Labour (Co-op)":
return "Labour";
case "Social Democratic & Labour Party":
return "SDLP";
case "Alba Party":
return "Alba";
case "Ulster Unionist Party":
return "UUP";
case "Traditional Unionist Voice":
return "TUV";
case "Independent":
return "Ind";
case "Reform UK":
return "Reform";
case "Green Party":
return "Green";
default:
return party;
}
}
static getClassName(party) {
return String(Util.shortenPartyName(party)).replace(/ /g, "").toLowerCase();
}
}