UNPKG

@wordpress/components

Version:
36 lines (35 loc) • 1.1 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let path_to_regexp = require("path-to-regexp"); // packages/components/src/navigator/utils/router.ts function matchPath(path, pattern) { return (0, path_to_regexp.match)(pattern, { decode: decodeURIComponent })(path); } function patternMatch(path, screens) { for (const screen of screens) { const matched = matchPath(path, screen.path); if (matched) return { params: matched.params, id: screen.id }; } } function findParent(path, screens) { if (!path.startsWith("/")) return; const pathParts = path.split("/"); let parentPath; while (pathParts.length > 1 && parentPath === void 0) { pathParts.pop(); const potentialParentPath = pathParts.join("/") === "" ? "/" : pathParts.join("/"); if (screens.find((screen) => { return matchPath(potentialParentPath, screen.path) !== false; })) parentPath = potentialParentPath; } return parentPath; } exports.findParent = findParent; exports.patternMatch = patternMatch; //# sourceMappingURL=router.cjs.map