forked from w3c/webref
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (29 loc) · 1.01 KB
/
index.js
File metadata and controls
32 lines (29 loc) · 1.01 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
const fs = require('fs').promises;
const path = require('path');
async function listAll({folder = __dirname} = {}) {
const json = await fs.readFile(path.join(folder, 'css.json'), 'utf8');
return JSON.parse(json);
}
async function index({folder = __dirname} = {}) {
const nonIndexed = await listAll(folder);
const indexed = {};
for (const [category, features] of Object.entries(nonIndexed)) {
indexed[category] = {};
for (const feature of features) {
// A handful of features have different definitions for different scopes.
// When that happens, the feature identifier needs to be disambiguated.
let id = feature.name;
let dupl = null;
if (feature.for) {
dupl = features.find(f => f !== feature && f.name === feature.name);
}
if (dupl) {
// Note: scopes of different definitions are necessarily disjoint
id += ' for ' + feature.for[0];
}
indexed[category][id] = feature;
}
}
return indexed;
}
module.exports = {listAll, index};