+1
-45
@@ -0,49 +1,5 @@ | ||
| import { parse } from 'regexparam'; | ||
| import { useBrowserLocation, useSearch as useSearch$1 } from './use-browser-location.js'; | ||
| import { createContext, forwardRef, useEvent, isValidElement, cloneElement, createElement, useContext, useRef, useIsomorphicLayoutEffect, Fragment } from './react-deps.js'; | ||
| /** | ||
| * The function below was extracted from the `regexparam` package. | ||
| * It has been modified to support optional wildcards, which is | ||
| * addressed in this PR https://github.com/lukeed/regexparam/pull/25 | ||
| * | ||
| * The original source code is distributed under the MIT license | ||
| * and is available at: https://github.com/lukeed/regexparam | ||
| * | ||
| * Copyright: Luke Edwards | ||
| */ | ||
| function parse(str, loose) { | ||
| if (str instanceof RegExp) return { keys: false, pattern: str }; | ||
| var c, | ||
| o, | ||
| tmp, | ||
| ext, | ||
| keys = [], | ||
| pattern = "", | ||
| arr = str.split("/"); | ||
| arr[0] || arr.shift(); | ||
| while ((tmp = arr.shift())) { | ||
| c = tmp[0]; | ||
| if (c === "*") { | ||
| o = tmp[1] === "?"; | ||
| keys.push("wild"); | ||
| pattern += o ? "(?:/(.*))?" : "/(.*)"; | ||
| } else if (c === ":") { | ||
| o = tmp.indexOf("?", 1); | ||
| ext = tmp.indexOf(".", 1); | ||
| keys.push(tmp.substring(1, !!~o ? o : !!~ext ? ext : tmp.length)); | ||
| pattern += !!~o && !~ext ? "(?:/([^/]+?))?" : "/([^/]+?)"; | ||
| if (!!~ext) pattern += (!!~o ? "?" : "") + "\\" + tmp.substring(ext); | ||
| } else { | ||
| pattern += "/" + tmp; | ||
| } | ||
| } | ||
| return { | ||
| keys: keys, | ||
| pattern: new RegExp("^" + pattern + (loose ? "(?=$|/)" : "/?$"), "i"), | ||
| }; | ||
| } | ||
| /* | ||
@@ -50,0 +6,0 @@ * Transforms `path` into its relative `base` version |
+2
-2
| { | ||
| "name": "wouter", | ||
| "version": "3.0.0-rc.1", | ||
| "version": "3.0.0-rc.2", | ||
| "description": "Minimalist-friendly ~1.5KB router for React", | ||
@@ -70,5 +70,5 @@ "type": "module", | ||
| "mitt": "^3.0.1", | ||
| "regexparam": "^2.0.1", | ||
| "regexparam": "^3.0.0", | ||
| "use-sync-external-store": "^1.0.0" | ||
| } | ||
| } |
+1
-1
@@ -33,3 +33,3 @@ // Minimum TypeScript Version: 4.1 | ||
| import { RouteParams } from "./regexparam.js"; | ||
| import { RouteParams } from "regexparam"; | ||
@@ -36,0 +36,0 @@ /** |
| export function parse( | ||
| route: string, | ||
| loose?: boolean | ||
| ): { | ||
| keys: string[]; | ||
| pattern: RegExp; | ||
| }; | ||
| export function parse(route: RegExp): { | ||
| keys: false; | ||
| pattern: RegExp; | ||
| }; | ||
| export type RouteParams<T extends string> = | ||
| T extends `${infer Prev}/*/${infer Rest}` | ||
| ? RouteParams<Prev> & { wild: string } & RouteParams<Rest> | ||
| : T extends `${string}:${infer P}?/${infer Rest}` | ||
| ? { [K in P]?: string } & RouteParams<Rest> | ||
| : T extends `${string}:${infer P}/${infer Rest}` | ||
| ? { [K in P]: string } & RouteParams<Rest> | ||
| : T extends `${string}:${infer P}?` | ||
| ? { [K in P]?: string } | ||
| : T extends `${string}:${infer P}` | ||
| ? { [K in P]: string } | ||
| : T extends `${string}*` | ||
| ? { wild: string } | ||
| : T extends `${string}*?` | ||
| ? { wild?: string } | ||
| : {}; |
25235
-7.24%12
-7.69%669
-9.1%+ Added
- Removed
Updated