UNPKG

gics-data

Version:

Modern library to parse, manipulate, and find GICS codes based on Global Industry Classification Standard by MSCI.

48 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.renderNested = renderNested; const _20230318_1 = require("./versions/20230318"); function renderNested() { const nestedElements = []; // First pass: create all elements with parents Object.entries(_20230318_1.classificationPlain).forEach(([key, element]) => { let parent = undefined; const targetLength = key.length / 2 - 1; if (![0, 1, 2, 3].includes(targetLength)) return; const parentCode = key.substring(0, 2 * targetLength); if (targetLength != 0) parent = { ..._20230318_1.classificationPlain[parentCode], code: parentCode, }; // Create nested element and add to array const nestedElement = { ...element, code: key, parent }; nestedElements.push(nestedElement); }); // Second pass: add children to each element nestedElements.forEach(element => { const children = []; const childCodeLength = element.code.length + 2; // Find all elements that are direct children nestedElements.forEach(potentialChild => { if (potentialChild.code.length === childCodeLength && potentialChild.code.startsWith(element.code)) { children.push({ code: potentialChild.code, name: potentialChild.name, description: potentialChild.description }); } }); element.children = children.length > 0 ? Object.fromEntries(children.map(element => [element.code, element])) : undefined; }); return Object.fromEntries(nestedElements.map(element => [element.code, element])); } //# sourceMappingURL=transformer-nesting.js.map