0.5.0 • Published 5 years ago

routekit-resolver v0.5.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

routekit-resolver

RouteKit resolver for browser environments.

Installation

NPM package routekit-resolver provides a commonjs, es2015 modules and TypeScript typings.

npm install -D routekit-resolver

Usage Example

import { resolve } from "routekit-resolver";

// routekit:emit("routes")
const ROUTES = {
  f: [35, 38, 33, 7],
  p: ["user/", "/edit"],
  s: [0, 1, 2],
};
// routekit:end

const match = (path) => resolve(ROUTES, path);

match("/user/123");

API

export interface ResolveResult<T> {
  readonly state: T;
  readonly vars: string[];
}

export function resolve<T>(map: RouteMap<T>, path: string): ResolveResult<T> | null;

resolve() function has 2 parameters:

  • map is a reference to a routes map.
  • path is a path that should be resolved.

When resolve function returns null value it means that no match was found.

0.5.0

5 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.1.0

7 years ago

0.0.1

7 years ago