import { TreeNode , TreeNodeRaw } from './interfaces' ; import { generateUniqueId } from './generateUniqueId' ; export param { Tree } tree param { number } depth requires returns { Tree } export function addUniqueId ( tree , depth = 0 ) { return tree . map ( node => { let treeNode ; treeNode = { label : node . label , id : generateUniqueId ( ) , depth } ; if ( node . children ) { const children = addUniqueId ( node . children , depth + 1 ) ; treeNode = { ... treeNode , children , options : children . map ( ( { id } ) => id ) } ; } if ( node . method ) { treeNode = { ... treeNode , method : node . method } ; } return treeNode ; } ) ; }