-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvalidation.js
38 lines (35 loc) · 1.74 KB
/
validation.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
function validateDistributions(distributions) {
return distributions.reduce(function(errors,distro) {
return errors.concat(validateDistribution(distro));
},[]);
}
function validateDistribution(distro) {
var errors = [];
function pushError(description) { errors.push({distribution: distro.id, description: description}); }
try {
if (!distro.id) { pushError('No id for distro'); }
if (!distro.name) { pushError('No name for distro'); }
if (!distro.url) { pushError('No website for distro'); }
if (distro.releases.length === 0) {
pushError('No releases');
}
distro.releases.forEach(function(release) {
if (!release) { pushError('Release is null'); return; }
if (typeof release !== 'object') { pushError('Release is not an object'); return; }
if (!release.url) { pushError('Release does not have an url'); }
if (!release.size) { pushError('Release "'+release.url+'" does not have a size'); }
// Version is optional.
//if (!release.version) { pushError('Release "'+release.url+'" does not have an version'); }
if (!/^https?:\/\//.test(release.url)) { pushError('Release "'+release.url+'" is not an url'); }
if (/\s+/.test(release.url)) { pushError('Release "'+release.url+'" has whitespace in its url'); }
if (distro.releases.filter(function(o) { return o && o.url === release.url; }).length > 1) { pushError('Duplicate url "'+release.url+'".'); }
});
} catch (e) {
pushError('Exception while validating: "' + e + '".');
}
return errors;
}
module.exports = {
validateDistributions: validateDistributions,
validateDistribution: validateDistribution
};