forked from w3c/browser-specs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (38 loc) · 1.22 KB
/
index.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
"use strict";
const specs = require("./index.json");
/**
* Return the list of specs that match the specified filter.
*
* - If the filter is an integer, return the spec at that index in the list
* - If the filter is full or delta, return specs with same level composition
* - If the filter is empty, return the whole list
* - return specs that have the same URL, name, shortname, or source otherwise
*/
function getSpecs(filter) {
if (filter) {
const res = filter.match(/^\d+$/) ?
[specs[parseInt(filter, 10)]] :
specs.filter(s =>
s.url === filter ||
s.name === filter ||
s.seriesComposition === filter ||
s.source === filter ||
s.title === filter ||
(s.series && s.series.shortname === filter) ||
(s.release && s.release.url === filter) ||
(s.nightly && s.nightly.url === filter));
return res;
}
else {
return specs;
}
}
if (require.main === module) {
// Code used as command-line interface (CLI), output info about known specs.
const res = getSpecs(process.argv[2]);
console.log(JSON.stringify(res.length === 1 ? res[0] : res, null, 2));
}
else {
// Code referenced from another JS module, export
module.exports = { getSpecs };
}