export const traverseChildren = (target, fn) => {
    const traverse = (node) => {
        if (node.children) {
            for (let index = 0; index < node.children.length; index++) {
                const child = node.children[index];
                const cont = fn(child);
                if (cont) {
                    if (child.children && child.children.length) {
                        traverse(child);
                    }
                }
            }
        }
    };
    traverse(target);
};
/**
 * Find children by name, returns first result
 * @example
 * ```
const room = getRoom({ p: [0, 0.1, 0], wallTypes: ['PLAIN', 'PLAIN', 'DOOR', 'PLAIN'] });
const ch = findChildren('wallNorth', room);
 * ```
 */
export const findChildren = (name, target) => {
    if (!name)
        return null;
    let result = null;
    traverseChildren(target, node => {
        let childName = '';
        if (node.name)
            childName = node.name;
        if (childName && childName === name) {
            result = node;
            return false;
        }
        else {
            return true;
        }
    });
    return result;
};
//# sourceMappingURL=findChildren.js.map