clean up router utils

This commit is contained in:
Niels Lyngsø
2023-04-12 09:22:18 +02:00
parent 76cea853ff
commit 2016f4ec03

View File

@@ -1,16 +1,7 @@
import type { ISlashOptions } from '@umbraco-cms/backoffice/router';
import { stripSlash } from '@umbraco-cms/backoffice/router';
const PARAM_IDENTIFIER = /:([^\\/]+)/g;
function stripSlash(path: string): string {
return slashify(path, { start: false, end: false });
}
function slashify(path: string, { start = true, end = true }: Partial<ISlashOptions> = {}): string {
path = start && !path.startsWith('/') ? `/${path}` : !start && path.startsWith('/') ? path.slice(1) : path;
return end && !path.endsWith('/') ? `${path}/` : !end && path.endsWith('/') ? path.slice(0, path.length - 1) : path;
}
export function generateRoutePathBuilder(path: string) {
return (params: { [key: string]: string | number }) =>
stripSlash(