github.com/hernad/nomad@v1.6.112/ui/app/utils/compact-path.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 /** 7 * Takes a branch created by our path-tree, and if it has only a single directory as descendent and no files, compacts it down to its terminal folder (the first descendent folder with either files or branching directories) 8 * Uses tail recursion 9 * @param {import("./path-tree").NestedPathTreeNode} branch 10 * @returns 11 */ 12 export default function compactPath(branch, name = '') { 13 let { children, files } = branch; 14 if (children && Object.keys(children).length === 1 && !files.length) { 15 const [key] = Object.keys(children); 16 const child = children[key]; 17 return compactPath(child, `${name}/${key}`); 18 } 19 return { 20 name, 21 data: branch, 22 }; 23 }