function filterTreeByName(nodes, searchName, options = { nameKey: "name", childrenKey: "children" }) {
  const { nameKey, childrenKey } = options;
  return nodes.map((node) => {
    const matches = node[nameKey]?.includes(searchName);
    const filteredChildren = node[childrenKey] ? filterTreeByName(node[childrenKey], searchName, options) : [];
    if (matches || filteredChildren.length > 0) {
      return {
        ...node,
        [childrenKey]: filteredChildren
      };
    } else {
      return null;
    }
  }).filter((node) => node !== null);
}

export { filterTreeByName };
//# sourceMappingURL=filterTreeByName.mjs.map
