UNPKG

@studiometa/js-toolkit

Version:

A set of useful little bits of JavaScript to boost your project! 🚀

31 lines (30 loc) • 990 B
import { isArray } from "../utils/index.js"; function getDirectChildren(parentInstance, parentName, childrenName) { const children = parentInstance.$children[childrenName]; const nestedParents = parentInstance.$children[parentName]; if (!isArray(children)) { return []; } if (!isArray(nestedParents) || nestedParents.length <= 0) { return children; } const directChildren = []; for (const child of children) { for (const nestedParent of nestedParents) { const nestedChildren = nestedParent.$children[childrenName]; if (isArray(nestedChildren) && nestedChildren.includes(child)) { continue; } directChildren.push(child); } } return directChildren; } function isDirectChild(parentInstance, parentName, childrenName, childInstance) { return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance); } export { getDirectChildren, isDirectChild }; //# sourceMappingURL=getDirectChildren.js.map