UNPKG

bidasoa-components

Version:

Colección de componentes comunes empleados en proyectos Bidasoa.

30 lines (29 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getParentLinkForPath = exports.getLinkByPathname = exports.getLinks = void 0; const FlattenedLink_1 = require("./FlattenedLink"); function getLinks(menu) { return menu.data.menu.links; } exports.getLinks = getLinks; function getLinkByPathname(mainMenu, pathname) { return (0, FlattenedLink_1.getFlatennedLinks)(getLinks(mainMenu)).find(element => { return element.link.url.path === pathname; }); } exports.getLinkByPathname = getLinkByPathname; function getParentLinkForPath(menu, path) { const flattenedLinks = (0, FlattenedLink_1.getFlatennedLinks)(getLinks(menu)); const currentLink = flattenedLinks.find(link => { return (Boolean(link.link.url) && removeTrailingSlashes(link.link.url.path) === removeTrailingSlashes(path)); }); if (!currentLink) { return undefined; } return currentLink.parent; } exports.getParentLinkForPath = getParentLinkForPath; function removeTrailingSlashes(rawPath) { return rawPath.replace(/\/+$/, ''); }