MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / categorizeChanges

Function categorizeChanges

apps/site/scripts/compare-size/index.mjs:31–57  ·  view source on GitHub ↗
(oldAssets, newAssets)

Source from the content-addressed store, hash-verified

29 * Categorizes asset changes
30 */
31const categorizeChanges = (oldAssets, newAssets) => {
32 const oldMap = new Map(oldAssets.map(a => [a.name, a]));
33 const newMap = new Map(newAssets.map(a => [a.name, a]));
34 const changes = { added: [], removed: [], modified: [] };
35
36 for (const [name, oldAsset] of oldMap) {
37 const newAsset = newMap.get(name);
38 if (!newAsset) {
39 changes.removed.push({ name, size: oldAsset.size });
40 } else if (oldAsset.size !== newAsset.size) {
41 changes.modified.push({
42 name,
43 oldSize: oldAsset.size,
44 newSize: newAsset.size,
45 delta: newAsset.size - oldAsset.size,
46 });
47 }
48 }
49
50 for (const [name, newAsset] of newMap) {
51 if (!oldMap.has(name)) {
52 changes.added.push({ name, size: newAsset.size });
53 }
54 }
55
56 return changes;
57};
58
59/**
60 * Builds a collapsible table section

Callers 1

reportDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected