-
Notifications
You must be signed in to change notification settings - Fork 2
/
validator.js
69 lines (56 loc) · 2.16 KB
/
validator.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
60
61
62
63
64
65
66
67
// 'use strict';
const families = require('./families');
const fetch = require("node-fetch");
function findDuplicate(data) {
const result = [];
data.forEach((item) => {
if (result.indexOf(item) === -1 && data.filter((i) => i.toLowerCase() === item.toLowerCase()).length > 1) {
result.push(item);
}
});
return result;
}
const fetchSeries = (url, page = 1, previousResponse = []) => {
return fetch(`${url}&page=${page}`)
.then(response => response.json())
.then((response2) => {
const response = [...previousResponse, ...response2._links['specification-series']];
if (page < response2.pages) {
return fetchSeries(url, page + 1, response);
}
return response;
});
};
(async function() {
const W3CSeries = await fetchSeries(`https://api.w3.org/specification-series?retired=false`);
const W3CSeriesTitles = W3CSeries.map((item) => item.title);
let hasErrors = false;
// check family name uniqueness
const duplicateFamilyNames = findDuplicate(families.map((f) => f.name));
if (duplicateFamilyNames.length > 0) {
console.error(`* Duplicate family names: ${duplicateFamilyNames}`);
hasErrors = true;
}
// check series uniqueness
const series = [].concat(...families.map(family => family.series));
const duplicateSeries = findDuplicate(series);
if (duplicateSeries.length > 0) {
console.error(`* Duplicate series: ${duplicateSeries}`);
hasErrors = true;
}
// check that all series from the API are listed in the families.json
let diff = W3CSeriesTitles.filter(s => !series.includes(s));
if (diff.length > 0) {
console.error(`* The following series are missing from families.json: ${diff}`);
hasErrors = true;
}
// check that all series from the families.json are listed in the API
diff = series.filter(s => !W3CSeriesTitles.includes(s));
if (diff.length > 0) {
console.error(`* The following series are unknown to the W3C API: ${diff}`);
hasErrors = true;
}
if (hasErrors) {
process.exit(1);
};
}());