Comparing version 0.1.1 to 0.2.0
export * from "./nav-opts"; | ||
export * from "./route-resolver"; | ||
export { Guard, GuardResult, Resolve, RouteSpec } from "./route-spec"; | ||
export * from "./router"; |
import { NavOpts } from "./nav-opts"; | ||
import { Resolve, RouteSpec } from "./route-spec"; | ||
export interface Resolved<T> { | ||
@@ -6,8 +7,2 @@ value: T; | ||
} | ||
export declare type Resolve<T> = (navOpts: NavOpts) => T | NavOpts | Promise<T | NavOpts>; | ||
export declare type GuardResult = void | false | NavOpts; | ||
export declare type Guard = (route: NavOpts) => GuardResult | Promise<GuardResult>; | ||
export declare type RouteSpec<T> = { | ||
[K in string]: K extends "/" ? Resolve<T> : K extends "?" ? Guard : RouteSpec<T>; | ||
} | Resolve<T>; | ||
export declare class RouteResolver { | ||
@@ -14,0 +9,0 @@ private maxRedirects; |
@@ -35,3 +35,3 @@ import { NavOpts } from "./nav-opts"; | ||
const child = this._getRouteChild(route, opts, part); | ||
const guardResult = await ((_a = route["?"]) === null || _a === void 0 ? void 0 : _a(opts)); | ||
const guardResult = await ((_a = route["?"]) === null || _a === void 0 ? void 0 : _a.call(route, opts)); | ||
if (guardResult) | ||
@@ -38,0 +38,0 @@ return () => guardResult; |
import { NavMeta, NavOpts, PathOrHref } from "./nav-opts"; | ||
import { Resolve, Resolved, RouteSpec } from "./route-resolver"; | ||
import { Resolved } from "./route-resolver"; | ||
import { Resolve, RouteSpec } from "./route-spec"; | ||
export declare type OnResolveListener<T> = (resolved: Resolved<T>) => void; | ||
@@ -4,0 +5,0 @@ export interface RouterConf<T> { |
import { NavOpts } from "./nav-opts"; | ||
import { RouteResolver } from "./route-resolver"; | ||
import { compileRoutes } from "./route-spec"; | ||
export class Router { | ||
@@ -30,2 +31,3 @@ constructor(routes = {}, { notFound = ({ go }) => go([]), noClick = false } = {}) { | ||
}; | ||
compileRoutes(routes); | ||
this._notFound = notFound; | ||
@@ -32,0 +34,0 @@ this._initListeners(noClick); |
{ | ||
"name": "esroute", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "A small efficient framework-agnostic client-side routing library, written in TypeScript.", | ||
@@ -20,11 +20,11 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@swc/cli": "^0.1.51", | ||
"@swc/core": "^1.2.108", | ||
"@swc/jest": "^0.2.5", | ||
"@types/jest": "^27.0.2", | ||
"jest": "^27.3.1", | ||
"jest-mock": "^27.4.2", | ||
"@swc/cli": "^0.1.57", | ||
"@swc/core": "^1.2.164", | ||
"@swc/jest": "^0.2.20", | ||
"@types/jest": "^27.4.1", | ||
"jest": "^27.5.1", | ||
"jest-mock": "^27.5.1", | ||
"regenerator-runtime": "^0.13.9", | ||
"typescript": "^4.4.4" | ||
"typescript": "^4.6.3" | ||
} | ||
} |
@@ -70,3 +70,3 @@ # esroute | ||
esroute comes with no dependencies and is quite small. The route spec object that is passed into the router instance is not processed and is very concise. | ||
esroute comes with no dependencies and is quite small. The route spec object that is passed into the router instance has only minimal processing to provide more configuration comfort. | ||
@@ -129,2 +129,3 @@ The route resolution is done by traversing the route spec tree and this algorithm is based on simple string comparisons (no regex matching). | ||
}, | ||
"/nested/deep-url/*/test": ({ params: [myParam] }) => resolveFoo(myParam), | ||
} | ||
@@ -131,0 +132,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
28487
18
331
169