How to use chemin - 3 common examples

To help you get started, we’ve selected a few chemin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github etienne-dldc / tumau / packages / tumau-router / src / Route.ts View on Github external
.map((childRoute): Route | null => {
          const middlewares = [...parentMiddleware, ...childRoute.middleware];
          const patterns = [route.pattern, childRoute.pattern];
          if (childRoute.pattern && route.exact) {
            console.warn(
              `Error: ${route.pattern} is expected to be exact but its children ${childRoute.pattern} has a pattern, the child pattern will be ignored`
            );
            patterns[1] = null;
          }
          const pattern = Chemin.create(...patterns.filter(Chemin.isChemin));
          const exact = route.exact || childRoute.exact;
          const method = combineMethods(route.method, childRoute.method, m => {
            console.warn(
              `Error: in ${route.pattern} > ${route.pattern} the Method ${m} is not allowed by parent. It will be ignored !`
            );
          });
          return createRoute({ pattern, exact, method }, middlewares, childRoute.children);
        })
        .filter((r: Route | null): r is Route => r !== null)
github etienne-dldc / tumau / packages / tumau-router / src / Route.ts View on Github external
function createRoute(
  options: RouteOptions,
  middleware: null | Middleware | Array,
  children: Routes = []
): Route {
  const { exact = true, method = null, pattern = null } = options;
  const patternResolved = typeof pattern === 'string' ? Chemin.parse(pattern) : pattern;
  return {
    [ROUTE_TOKEN]: true,
    pattern: patternResolved,
    exact,
    middleware: resolveMiddleware(middleware),
    method,
    children,
  };
}
github etienne-dldc / tumau / packages / tumau-router / src / Route.ts View on Github external
function find(routes: Array, pathname: string): Array {
  const parts = CheminUtils.splitPathname(pathname);
  return routes
    .map((route, index): FindResult | false => {
      if (route.pattern === null) {
        return {
          route,
          index,
          params: {},
        };
      }
      const match = route.pattern.match(parts);

      if (match === false) {
        return false;
      }
      if (route.exact && match.rest.length > 0) {
        return false;

chemin

A type-safe pattern builder & route matching library written in TypeScript

MIT
Latest version published 2 years ago

Package Health Score

42 / 100
Full package analysis