UNPKG

element-book

Version:

An [`element-vir`](https://npmjs.com/package/element-vir) drop-in element for building, testing, and demonstrating a collection of elements (or, in other words, a design system).

41 lines (40 loc) 1.13 kB
import { collapseWhiteSpace } from '@augment-vir/common'; /** * Create a list of URL breadcrumbs for the given element-book entry. * * @internal */ export function listUrlBreadcrumbs(entry, includeSelf) { const entryBreadcrumb = titleToUrlBreadcrumb(entry.title); if (entry.parent) { return [ ...listUrlBreadcrumbs(entry.parent, false), titleToUrlBreadcrumb(entry.parent.title), ].concat(includeSelf ? [entryBreadcrumb] : []); } else if (includeSelf) { return [entryBreadcrumb]; } else { return []; } } /** * Convert an element-book entry's title to a URL-safe breadcrumb title. * * @internal */ export function titleToUrlBreadcrumb(title) { return collapseWhiteSpace(title).toLowerCase().replaceAll(/\s/g, '-'); } /** * Check if a full list of URL breadcrumbs (`searchIn`) starts with the subset list of URL * breadcrumbs (`searchFor`). * * @internal */ export function doBreadcrumbsStartWith({ searchFor, searchIn, }) { return searchFor.every((breadcrumb, index) => { return searchIn[index] === breadcrumb; }); }