-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-version.html
123 lines (104 loc) · 4.22 KB
/
node-version.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #d9e4cb;
}
.center {
margin: auto;
width: 40%;
border: 3px solid #73AD21;
padding: 10px;
}
table {
width: 100%;
border: 2px solid black;
}
th {
border: 1px solid #73AD21;
}
td {
text-align: center;
border: 1px solid #73AD21;
}
</style>
</head>
<body>
<div class="center">
<div id="output"></div>
</div>
<!-- <script src="index.js"></script> -->
<script>
let getAllData = {};
const getReleaseURL = (version) => version ? `https://nodejs.org/download/release/v${version}/` : '';
const getTitle = (version) => getAllData.filter(ele => ele.version === `v${version}`)[0].lts;
const getReleaseInfo = (version) => version ? `https://github.com/nodejs/node/releases/tag/v${version}/` : '';
function shoeCombinedData(arr1, arr2) {
if (arr1.length < arr2.length) {
let _temp = arr1; arr1 = arr2; arr2 = _temp;
}
let st = `<table>`;
st += `<tr>
<th>CURRENT</th>
<th>LTS Version</th>
</tr>`
for (let i = 0; i < arr2.length; i++) {
const currentVersion = arr1[i];
const ltsVersion = arr2[i] ? arr2[i] : '';
st += `<tr>
<th>
<a href="${getReleaseInfo(currentVersion)}" target="blank" title="View Release Note">
Release Note
</a> :
<a href="${getReleaseURL(currentVersion)}" target="blank" title="Current Version">
${currentVersion}
</a>
</th>
<th>
<a href="${getReleaseInfo(ltsVersion)}" target="blank" title="View Release Note">
${getTitle(ltsVersion)}
</a> :
<a href="${getReleaseURL(ltsVersion)}" target="blank" title="LTS">
${ltsVersion}
</a>
</th>
</tr>`;
}
st += `</table>`
document.getElementById("output").innerHTML = st;
}
function getRequestCall() {
const api_url = 'https://nodejs.org/dist/index.json';
let req = new XMLHttpRequest();
req.open("GET", api_url);
req.onload = () => {
if (req.readyState === XMLHttpRequest.DONE) {
if (req.status === 200) {
getAllData = JSON.parse(req.response);
const currentNodeVersions = getAllData.filter(x => !(x.lts === false)).map(x => x = x.version.replace(/v/gi, ''));
const ltsNodeVersion = getAllData.filter(x => (x.lts === false)).map(x => x = x.version.replace(/v/gi, ''));
shoeCombinedData(currentNodeVersions, ltsNodeVersion);
// const noLTS = JSON.parse(req.response).filter(x => !(x.lts === false)).filter((x,i) => i<20);
// console.log(noLTS);
// document.getElementById("output").innerHTML = noLTS.map(x => (x.version + " - " + x.lts)).join('</br>');
} else {
console.log(`Request failed with status code ${req.status} from url ${req.responseURL}`);
}
}
};
req.onerror = error => {
console.log(`Request failed with error ${error.type}`);
};
req.send();
}
function getVersion(_version) {
return getAllData.filter(x => x.version === _version);
}
function showVersionDetails(_version) {
const _data = getVersion(_version);
}
getRequestCall();
</script>
</body>
</html>