style(core): composable matcherFactory
MODIFY
packages/core/src/operators/matchPath/matcher.factory.ts
packages/core/src/operators/matchPath/matcher.factory.ts
-export const removeTrailingSlash = (path: string): string =>
- path.replace(/\/$/, '');
+import { compose } from '../../util/compose.util';
-export const removeQueryParams = (path: string): string => path.split('?')[0];
+export const applyPath = (path: string) => (url: string) => url + path;
+
+export const applySuffix = (suffix?: string) => (url: string) => url + (suffix || '');
+
+export const removeQueryParams = (url: string) => url.split('?')[0];
+
+export const removeTrailingSlash = (url: string) => url.replace(/\/$/, '');
+
+export const constructMatcher = (history: string[]) => history.reduce((prev, cur) => prev + cur, '');
export const matcherFactory = (
matchingHistory: string[],
pathToMatch: string,
suffix?: string
-): string =>
- removeTrailingSlash(
- matchingHistory.reduce((prev, cur) => prev + cur, '') +
- removeTrailingSlash(pathToMatch) +
- (suffix || '')
- );
+) =>
+ compose(
+ applySuffix(suffix),
+ removeTrailingSlash,
+ applyPath(pathToMatch),
+ constructMatcher,
+ )(matchingHistory);

style(core): composable matcherFactory