-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathUtil.js
51 lines (44 loc) · 1.22 KB
/
Util.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
Util = (function () {
return {
indexKey: indexKey,
indexShapeMap: indexShapeMap,
createResults: createResults
};
function indexKey (node, shape) {
return node+'@'+shape;
}
function indexShapeMap (fixedMap) {
return fixedMap.reduce((ret, ent) => {
ret[indexKey(ent.node, ent.shape)] = ent;
return ret;
}, {});
}
function createResults () {
var _shapeMap = [];
var known = {};
return {
// Get results ShapeMap.
getShapeMap: function () { return _shapeMap; },
// Add entries to results ShapeMap.
merge: function (toAdd) {
toAdd.forEach(ent => {
var key = indexKey(ent.node, ent.shape);
if (!(key in known)) {
_shapeMap.push(ent);
known[key] = ent;
}
});
return this;
},
has: function (ent) {
var key = indexKey(ent.node, ent.shape);
return (key in known);
},
report: function () {
log("<span class=\"results\">" + _shapeMap.map(elt => {
return "<span class=\"" + elt.status + "\">" + elt.node + "@" + (elt.status === "fail" ? "!" : "") + elt.shape + "</span>";
}).join("<br />\n") + "</span>");
}
};
}
})();