For start I have an array of URLs which I have crawled using a simple-crawler library.
The data received is what I want to transform into a tree structure or folder structure. I am using react-tabulator here because I wanted to resize columns of table. Now along with normal table, I want to have the nested folder view structure.
//input data
const urls = [
{ id: 1, address: 'https://happy.com' },
{ id: 2, address: 'https://happy.com/about' },
{ id: 3, address: 'https://happy.com/contact' },
{ id: 4, address: 'https://happy.com/contact/office' },
{ id: 5, address: 'https://happy.com/contact/home' },
{ id: 6, address: 'https://happy.com/projects' },
];
//output data
tableDataNested = [
{ id: 1, address: 'https://happy.com',
_children:[
{ id: 2, address: 'https://happy.com/about', _children:[] },
{ id: 3, address: 'https://happy.com/contact',
_children:[
{ id: 4, address: 'https://happy.com/contact/office', _children:[] },
{ id: 5, address: 'https://happy.com/contact/home', _children:[] },
]
},
{ id: 6, address: 'https://happy.com/projects', _children:[] },
]
}
];
Though I saw 1-2 posts resembling this concept, I wasn’t sure on the pure JS way of doing or probably use some nice libraries too. Any insights anyone?