UNPKG

next-compose-middleware

Version:

`next-compose-middleware` is a library that simplifies building complex, declarative middleware for Next.js applications. It allows you to create highly readable and maintainable middleware by composing multiple functions together.

28 lines 910 B
export const getDividedPaths = (path) => { const exceptHeadEmpty = path.split('/').slice(1); const exceptTailEmpty = exceptHeadEmpty.at(-1) === '' ? exceptHeadEmpty.slice(0, -1) : exceptHeadEmpty; return exceptTailEmpty; }; export const toPath = (path) => { return path.startsWith('/') ? path : `/${path}`; }; export const isDynamicPath = (path) => { const dynamicPathregex = /^\/\[\w+\]$/; return dynamicPathregex.test(path); }; export const findPathValue = (pathMap, path) => { var _a; const value = pathMap[path]; if (value) { return value; } const found = Object.keys(pathMap).find((key) => isDynamicPath(key)); const dynamicPath = found ? toPath(found) : null; if (dynamicPath === null) { return null; } return (_a = pathMap[dynamicPath]) !== null && _a !== void 0 ? _a : null; }; //# sourceMappingURL=path.js.map