// utility.ts import { slug } from '@digigov/ui/navigation/Breadcrumbs/slug'; export const flattenRoutes = ( items, maxLength = 15, prepend = '', parents: string[] = [] ) => { let flattened = {}; items.forEach((value) => { const { title, href, children, ...rest } = value; const route = [prepend, href || slug(title, maxLength)].join('/'); const routeChildren = children ? children.map((child) => ({ href: child.href || slug(child.title, maxLength), ...child, })) : []; flattened[route] = { ...rest, title, children: routeChildren, parents, }; if (children) { flattened = { ...flattened, ...flattenRoutes(children, maxLength, route, [...parents, title]), }; } }); return flattened; };