UNPKG

trm-core

Version:

TRM (Transport Request Manager) Core

28 lines (27 loc) 765 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPackageHierarchy = getPackageHierarchy; function getPackageHierarchy(input) { const map = new Map(); input.forEach(item => { map.set(item.devclass, { devclass: item.devclass, sub: [] }); }); const roots = []; input.forEach(item => { const child = map.get(item.devclass); const parent = map.get(item.parentcl); if (child && parent) { parent.sub.push(child); } else if (child && !parent) { roots.push(child); } }); if (roots.length > 1) { throw new Error(`Multiple roots found in package hierarchy.`); } return roots[0]; }