react-routes-forge 1.1.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,79 +1,75 @@
1
+ import { Q as QueryParams, R as RouteParams, B as BuildPathOptions, F as FlatRoute, a as BreadcrumbOptions, b as BreadcrumbItem, P as PathParams, c as RoutePath, E as ExtractParams, d as RouteTree } from './index-Beg7xp8k.js';
2
+ export { M as MatchPathOptions, e as RouteBuilder, f as RouteLeaf, g as RouteMap, h as RouteParam } from './index-Beg7xp8k.js';
3
+
1
4
  /**
2
- * A static route string (template or resolved), e.g. '/users/:id' or '/users/42'
3
- */
4
- type RoutePath = `/${string}`;
5
- /**
6
- * A route builder function that accepts params and returns a resolved path.
7
- */
8
- type RouteBuilder<TParams extends RouteParams = RouteParams> = (params: TParams) => RoutePath;
9
- /**
10
- * Acceptable param value types for route builders.
11
- */
12
- type RouteParam = string | number;
13
- type RouteParams = Record<string, RouteParam>;
14
- /**
15
- * A leaf node in a route definition: either a static path or a builder function.
16
- */
17
- type RouteLeaf = RoutePath | RouteBuilder;
18
- /**
19
- * Recursively defines a route map: each key is either a leaf or a nested map.
20
- */
21
- type RouteMap = {
22
- [key: string]: RouteLeaf | RouteMap;
23
- };
24
- /**
25
- * Extracts param names from a path template string.
26
- * e.g. '/users/:id/posts/:postId' → 'id' | 'postId'
5
+ * Emits a `console.warn` in non-production environments.
6
+ * Shared by the core utilities and `defineRoutes()` so the production check
7
+ * lives in one place.
27
8
  */
28
- type StripOptional<S extends string> = S extends `${infer Name}?` ? Name : S;
29
- type ExtractParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? StripOptional<Param> | ExtractParams<`/${Rest}`> : T extends `${string}:${infer Param}` ? StripOptional<Param> : never;
9
+ declare function devWarn(message: string): void;
30
10
  /**
31
- * Builds a params object type from a path template.
32
- * e.g. '/users/:id' { id: RouteParam }
11
+ * Clears internal regex cache maps (PREFIX_CACHE and PATH_CACHE).
12
+ * Useful in test suites to prevent cached patterns from leaking across test cases.
33
13
  */
34
- type PathParams<T extends string> = ExtractParams<T> extends never ? never : {
35
- [K in ExtractParams<T>]: RouteParam;
36
- };
14
+ declare function clearPathCache(): void;
37
15
  /**
38
- * Acceptable query param value types for route builders.
39
- */
40
- type QueryParams = Record<string, RouteParam | RouteParam[] | null | undefined>;
41
- /**
42
- * Options accepted by `buildPath` (4th positional argument).
16
+ * Append a query string and/or hash fragment to a path that may already
17
+ * contain a query or hash.
18
+ *
19
+ * - Existing query pairs are preserved; new ones are joined with `&`.
20
+ * - The query string is always inserted before any hash fragment, so an
21
+ * existing `#section` on `path` is kept unless a new `hash` is given.
43
22
  *
44
23
  * @example
45
- * // Throws a RangeError when a :param segment is missing rather than
46
- * // silently leaving the colon-placeholder in the output string.
47
- * buildPath('/users/:id', {}, undefined, { strict: true });
24
+ * ```ts
25
+ * appendQuery("/users?tab=list", { page: 2 }); // "/users?tab=list&page=2"
26
+ * appendQuery("/users#top", { tab: "list" }); // → "/users?tab=list#top"
27
+ * ```
48
28
  */
49
- type BuildPathOptions = {
50
- /**
51
- * When `true`, `buildPath` throws a `RangeError` if any `:param`
52
- * placeholder is left unresolved instead of emitting a console.warn.
53
- * Useful in dev/test environments to catch missing params early.
54
- */
55
- strict?: boolean;
56
- };
29
+ declare function appendQuery(path: string, query?: QueryParams, hash?: string): string;
57
30
  /**
58
- * A single entry produced by `flattenRoutes()`.
31
+ * Parse the query string out of a path (or bare query string) into a plain
32
+ * object. Repeated keys become arrays; a single key is a scalar string.
33
+ *
34
+ * With `{ coerceBooleans: true }`, the strings `"true"`/`"false"` are
35
+ * converted to actual booleans.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * extractQueryFromPath("/users/42?tab=profile&tag=a&tag=b");
40
+ * // → { tab: "profile", tag: ["a", "b"] }
41
+ * extractQueryFromPath("/search?active=true", { coerceBooleans: true });
42
+ * // → { active: true }
43
+ * ```
59
44
  */
60
- type FlatRoute = {
61
- /** Dot-joined key path from the root, e.g. `"SERVICES.BCC.EDIT"`. */
62
- key: string;
63
- /** The raw path template string, e.g. `"/services/bcc/edit/:id"`. */
64
- path: string;
65
- };
66
-
45
+ declare function extractQueryFromPath(path: string, options?: {
46
+ coerceBooleans?: boolean;
47
+ coerceNumbers?: boolean;
48
+ }): QueryParams;
67
49
  declare function buildPath(template: string, params: RouteParams, query?: QueryParams, options?: BuildPathOptions): string;
68
50
  declare function extractParamNames(template: string): string[];
69
51
  declare function isDynamic(path: string): boolean;
52
+ /**
53
+ * Test whether `currentPath` matches `template`, mirroring React Router's
54
+ * `NavLink` matching semantics:
55
+ *
56
+ * - Case-insensitive by default (pass `caseSensitive: true` to opt out).
57
+ * - Trailing slashes are tolerated (`/users/` matches `/users`).
58
+ * - `exact: true` (the default) requires a full match; `exact: false`
59
+ * matches any path that starts with the template.
60
+ */
70
61
  declare function isActivePath(currentPath: string, template: string, options?: {
71
62
  exact?: boolean;
63
+ caseSensitive?: boolean;
72
64
  }): boolean;
73
65
  declare function extractParamsFromPath(template: string, resolvedPath: string): Record<string, string>;
74
66
  declare function joinPaths(...segments: string[]): string;
75
67
  declare function build(template: string, params: RouteParams, query?: QueryParams, options?: BuildPathOptions): string;
76
68
  declare function getParamNames(template: string): string[];
69
+ declare function matchPath(template: string, options?: {
70
+ end?: boolean;
71
+ caseSensitive?: boolean;
72
+ }): RegExp;
77
73
  /**
78
74
  * Walk a `defineRoutes` output tree and return a flat array of
79
75
  * `{ key, path }` entries where `key` is the dot-joined key path from
@@ -91,67 +87,56 @@ declare function getParamNames(template: string): string[];
91
87
  * if (dupes.length) console.warn('Duplicate paths:', dupes);
92
88
  */
93
89
  declare function flattenRoutes(routes: Record<string, unknown>, prefix?: string): FlatRoute[];
94
-
95
- type RouteInput = {
96
- [key: string]: string | RouteInput;
97
- };
98
- type DynamicRoute<T extends string> = T extends `${string}:${string}` ? T & {
99
- build(params: PathParams<T>, query?: QueryParams, options?: BuildPathOptions): RoutePath;
100
- paramNames: Array<ExtractParams<T>>;
101
- } : T;
102
- type ResolvedRoutes<T extends RouteInput> = {
103
- [K in keyof T]: T[K] extends RouteInput ? ResolvedRoutes<T[K]> : T[K] extends string ? DynamicRoute<T[K]> : never;
104
- };
105
- declare function defineRoutes<T extends RouteInput>(routes: T): ResolvedRoutes<T>;
106
-
107
90
  /**
108
- * React integration hooks for route-forge.
109
- * These are thin wrappers — import only if you're using React Router.
110
- */
111
-
112
- /**
113
- * A typed wrapper around React Router's `useParams`.
91
+ * Build a breadcrumb trail from a route tree or a flat route list.
114
92
  *
115
- * @example
116
- * ```tsx
117
- * // Route: '/a/:x/b/:y/c/:z'
118
- * const { x, y, z } = useRouteParams<'/a/:x/b/:y/c/:z'>();
119
- * ```
120
- */
121
- declare function useRouteParams<T extends string>(): Record<ExtractParams<T>, string>;
122
- type NavigateOptions = {
123
- replace?: boolean;
124
- state?: unknown;
125
- };
126
- /**
127
- * A typed `navigate` helper that accepts a resolved path (output of `.build()`)
128
- * or a plain static path, with optional navigation options.
93
+ * For a given `currentPath`, it walks the route tree and returns every route
94
+ * that is an ancestor of (or an exact match to) the current page. Ancestors
95
+ * are matched by prefix (e.g. `/users` matches `/users/edit/42/posts`).
96
+ *
97
+ * Dynamic params in ancestor paths are automatically resolved from the
98
+ * matched portion of the URL.
99
+ *
100
+ * @param routes - A route tree (output of `defineRoutes`) or a pre-flattened
101
+ * array from `flattenRoutes()`.
102
+ * @param currentPath - The current URL (with or without query string).
103
+ * @param options - Optional label resolver.
104
+ * @returns An array of {@link BreadcrumbItem} ordered by depth
105
+ * (most general first), where the last item is the current page.
129
106
  *
130
107
  * @example
131
- * ```tsx
132
- * const navigateTo = useNavigateTo();
133
- * navigateTo(PATHS.USERS.EDIT.build({ id: 42 }));
134
- * navigateTo(PATHS.HOME, { replace: true });
108
+ * ```ts
109
+ * const PATHS = defineRoutes({
110
+ * HOME: "/",
111
+ * USERS: { ROOT: "/users", EDIT: "/users/edit/:id" },
112
+ * } as const);
113
+ *
114
+ * getBreadcrumbs(PATHS, "/users/edit/42");
115
+ * // → [
116
+ * // { key: "HOME", label: "Home", path: "/", isCurrent: false },
117
+ * // { key: "USERS.ROOT", label: "Users", path: "/users", isCurrent: false },
118
+ * // { key: "USERS.EDIT", label: "Edit", path: "/users/edit/42", isCurrent: true },
119
+ * // ]
135
120
  * ```
136
121
  */
137
- declare function useNavigateTo(): (path: string, options?: NavigateOptions) => void;
122
+ declare function getBreadcrumbs(routes: Record<string, unknown> | FlatRoute[], currentPath: string, options?: BreadcrumbOptions): BreadcrumbItem[];
123
+
138
124
  /**
139
- * Resolves a dynamic path template against params using React Router's
140
- * `generatePath`, with proper typing.
141
- *
142
- * Accepts the same `options` bag as `build()` / `buildPath()`:
143
- * - (default) soft-fail: `console.warn` and return the partial path with unresolved `:param` placeholders.
144
- * - `{ strict: true }`: throw a `RangeError` on missing params — matching `.build()`'s strict behaviour.
145
- *
146
- * When all params are present, resolution is delegated to React Router's `generatePath`,
147
- * which correctly handles splat (`*`) and optional (`:param?`) segments.
125
+ * A dynamic route is a template string with a `:param` or trailing `/*` splat,
126
+ * augmented with a `.build()` helper and a `.paramNames` array.
148
127
  *
149
- * @example
150
- * ```tsx
151
- * const path = useResolvedPath('/users/:id', { id: 42 }); // → '/users/42'
152
- * const path = useResolvedPath('/users/:id', {}, undefined, { strict: true }); // throws RangeError
153
- * ```
128
+ * Exported so consumers (e.g. the hooks entry) can type against it.
154
129
  */
155
- declare function useResolvedPath(template: string, params: RouteParams, query?: QueryParams, options?: BuildPathOptions): string;
130
+ type StaticRoute<T extends string> = T & {
131
+ build(query?: QueryParams, options?: BuildPathOptions): RoutePath;
132
+ };
133
+ type DynamicRoute<T extends string> = T extends `${string}:${string}` | `${string}/*` ? T & {
134
+ build(params: PathParams<T>, query?: QueryParams, options?: BuildPathOptions): RoutePath;
135
+ paramNames: Array<ExtractParams<T>>;
136
+ } : StaticRoute<T>;
137
+ type ResolvedRoutes<T extends RouteTree> = {
138
+ [K in keyof T]: T[K] extends RouteTree ? ResolvedRoutes<T[K]> : T[K] extends string ? DynamicRoute<T[K]> : never;
139
+ };
140
+ declare function defineRoutes<T extends RouteTree>(routes: T): ResolvedRoutes<T>;
156
141
 
157
- export { type BuildPathOptions, type ExtractParams, type FlatRoute, type PathParams, type QueryParams, type RouteBuilder, type RouteLeaf, type RouteMap, type RouteParam, type RouteParams, type RoutePath, build, buildPath, defineRoutes, extractParamNames, extractParamsFromPath, flattenRoutes, getParamNames, isActivePath, isDynamic, joinPaths, useNavigateTo, useResolvedPath, useRouteParams };
142
+ export { BreadcrumbItem, BreadcrumbOptions, BuildPathOptions, type DynamicRoute, ExtractParams, FlatRoute, PathParams, QueryParams, RouteParams, RoutePath, RouteTree, type StaticRoute, appendQuery, build, buildPath, clearPathCache, defineRoutes, devWarn, extractParamNames, extractParamsFromPath, extractQueryFromPath, flattenRoutes, getBreadcrumbs, getParamNames, isActivePath, isDynamic, joinPaths, matchPath };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var l=()=>/:([^/]+)/g,x=()=>/[.*+?^${}()|[\]\\]/g;function f(t){return t.replace(x(),"\\$&")}function R(t){return f(t).replace(l(),"([^/]+)")}function P(t,e){if(!e)return t;let r=new URLSearchParams;for(let[s,n]of Object.entries(e))n!=null&&(Array.isArray(n)?n.forEach(i=>{i!=null&&r.append(s,String(i))}):r.append(s,String(n)));let a=r.toString();return a?t+(t.includes("?")?"&":"?")+a:t}function p(t,e,r,a){let s=u(t),n=s.filter(o=>e[o]===void 0||e[o]===null),i=s.reduce((o,c)=>{let m=e[c],h=m==null?`:${c}`:String(m);return o.replace(new RegExp(`:${f(c)}\\??(?=/|$)`,"g"),h)},t);if(n.length>0){if(a?.strict)throw new RangeError(`[route-forge] Missing required param(s) ${n.map(c=>`":${c}"`).join(", ")} in template "${t}".`);globalThis.process?.env?.NODE_ENV!=="production"&&console.warn(`[route-forge] Unresolved params in path "${i}". Check that all :param segments have matching keys.`)}return P(i,r)}function u(t){return[...t.matchAll(l())].map(e=>e[1].replace(/\?$/,""))}function g(t){return l().test(t)}function T(t,e,r={exact:!0}){let a=t.split("?")[0]??"",s=R(e);return(r.exact?new RegExp(`^${s}$`):new RegExp(`^${s}`)).test(a)}function v(t,e){let r=e.split("?")[0]??"",a=u(t),s=new RegExp(`^${R(t)}$`),n=r.match(s);return n?Object.fromEntries(a.map((i,o)=>[i,n[o+1]??""])):{}}function b(...t){return"/"+t.map(e=>e.replace(/^\/+|\/+$/g,"")).filter(Boolean).join("/")}function E(t,e,r,a){return p(t,e,r,a)}function N(t){return u(t)}function d(t,e=""){let r=[];for(let a of Object.keys(t)){let s=e?`${e}.${a}`:a,n=t[a];typeof n=="string"?r.push({key:s,path:n}):n instanceof String?r.push({key:s,path:n.valueOf()}):typeof n=="object"&&n!==null&&r.push(...d(n,s))}return r}var O=t=>typeof t=="object"&&t!==null;function $(t){let e=u(t),r=new String(t);return r.build=(a,s,n)=>p(t,a,s,n),r.paramNames=e,r}function y(t){let e={};for(let r in t){if(!Object.prototype.hasOwnProperty.call(t,r))continue;let a=t[r];typeof a=="string"?e[r]=g(a)?$(a):a:O(a)&&(e[r]=y(a))}return e}function k(t){return y(t)}import{useParams as w,useNavigate as A,generatePath as Q}from"react-router-dom";function j(){return w()}function B(){let t=A();return(e,r)=>{t(e,r)}}function S(t,e,r,a){if(!u(t).every(o=>e[o]!==void 0&&e[o]!==null))return p(t,e,r,a);let i=Q(t,Object.fromEntries(Object.entries(e).map(([o,c])=>[o,String(c)])));return P(i,r)}export{E as build,p as buildPath,k as defineRoutes,u as extractParamNames,v as extractParamsFromPath,d as flattenRoutes,N as getParamNames,T as isActivePath,g as isDynamic,b as joinPaths,B as useNavigateTo,S as useResolvedPath,j as useRouteParams};
1
+ import{a as n,b as R,c as f,d as l,e as c,f as d,g as u,h as m,i as T,j as g,k as x,l as w,m as b,n as P,o as k}from"./chunk-EFHUAXKE.js";var O=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype;function $(t,e){t.startsWith("/")||n(`[route-forge] Route "${e}" does not start with "/": "${t}".`),t.includes("*")&&!t.endsWith("/*")&&n(`[route-forge] Route "${e}" uses "*" outside a trailing "/*" splat; only a trailing splat is supported: "${t}".`)}function v(t){let e=new Map,o=new Set,a=P(t);for(let r of a){let s=e.get(r.path);s===void 0?e.set(r.path,r.key):o.has(r.path)||(o.add(r.path),n(`[route-forge] Duplicate route path "${r.path}" for "${s}" and "${r.key}". Only one of them will be reachable.`))}for(let r=0;r<a.length;r++){let s=a[r];if(u(s.path))for(let p=r+1;p<a.length;p++){let i=a[p];if(!u(i.path)&&m(i.path,s.path,{exact:!0})){let h=`${s.key}->${i.key}`;o.has(h)||(o.add(h),n(`[route-forge] Route "${i.key}" ("${i.path}") is shadowed by dynamic route "${s.key}" ("${s.path}"). Place static routes before dynamic parameters in route trees.`))}}}}function B(t){let e=new String(t);return e.build=(o,a)=>c(t,{},o,a),e}function D(t){let e=d(t),o=new String(t);return o.build=(a,r,s)=>c(t,a,r,s),o.paramNames=e,o}function y(t){let e={};for(let o in t){if(!Object.prototype.hasOwnProperty.call(t,o))continue;let a=t[o];typeof a=="string"?($(a,o),e[o]=u(a)?D(a):B(a)):O(a)&&(e[o]=y(a))}return e}function Q(t){let e=y(t);return v(e),e}export{f as appendQuery,x as build,c as buildPath,R as clearPathCache,Q as defineRoutes,n as devWarn,d as extractParamNames,T as extractParamsFromPath,l as extractQueryFromPath,P as flattenRoutes,k as getBreadcrumbs,w as getParamNames,m as isActivePath,u as isDynamic,g as joinPaths,b as matchPath};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/utils.ts","../src/core/defineRoutes.ts","../src/hooks/index.ts"],"sourcesContent":["import type { QueryParams, RouteParam, RouteParams, BuildPathOptions, FlatRoute } from \"../types\";\n\n/** Returns a fresh RegExp each call — avoids shared `lastIndex` state on /g patterns. */\nconst PATH_PARAM_RE = () => /:([^/]+)/g;\nconst ESCAPE_RE = () => /[.*+?^${}()|[\\]\\\\]/g;\n\nfunction escapeRegex(value: string): string {\n return value.replace(ESCAPE_RE(), \"\\\\$&\");\n}\n\nfunction createTemplatePattern(template: string): string {\n return escapeRegex(template).replace(PATH_PARAM_RE(), \"([^/]+)\");\n}\n\nexport function appendQuery(path: string, query?: QueryParams): string {\n if (!query) return path;\n\n const searchParams = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue;\n if (Array.isArray(value)) {\n value.forEach((v) => {\n if (v !== undefined && v !== null) searchParams.append(key, String(v));\n });\n } else {\n searchParams.append(key, String(value));\n }\n }\n\n const queryString = searchParams.toString();\n if (!queryString) return path;\n\n return path + (path.includes(\"?\") ? \"&\" : \"?\") + queryString;\n}\n\nexport function buildPath(\n template: string,\n params: RouteParams,\n query?: QueryParams,\n options?: BuildPathOptions,\n): string {\n const paramNames = extractParamNames(template);\n const unresolved = paramNames.filter(\n (name) => params[name] === undefined || params[name] === null,\n );\n\n const resolved = paramNames.reduce((path, name) => {\n const value = params[name];\n const replacement = value === undefined || value === null ? `:${name}` : String(value);\n return path.replace(\n new RegExp(`:${escapeRegex(name)}\\\\??(?=/|$)`, \"g\"),\n replacement,\n );\n }, template);\n\n if (unresolved.length > 0) {\n if (options?.strict) {\n throw new RangeError(\n `[route-forge] Missing required param(s) ${unresolved.map((p) => `\":${p}\"`).join(\", \")} in template \"${template}\".`,\n );\n }\n\n const runtimeProcess = (\n globalThis as typeof globalThis & {\n process?: {\n env?: Record<string, string | undefined>;\n };\n }\n ).process;\n\n if (runtimeProcess?.env?.NODE_ENV !== \"production\") {\n console.warn(\n `[route-forge] Unresolved params in path \"${resolved}\". ` +\n `Check that all :param segments have matching keys.`,\n );\n }\n }\n\n return appendQuery(resolved, query);\n}\n\nexport function extractParamNames(template: string): string[] {\n return [...template.matchAll(PATH_PARAM_RE())].map(\n (match) => (match[1] as string).replace(/\\?$/, \"\"),\n );\n}\n\nexport function isDynamic(path: string): boolean {\n return PATH_PARAM_RE().test(path);\n}\n\nexport function isActivePath(\n currentPath: string,\n template: string,\n options: { exact?: boolean } = { exact: true },\n): boolean {\n const pathWithoutSearch = currentPath.split(\"?\")[0] ?? \"\";\n const pattern = createTemplatePattern(template);\n const regex = options.exact\n ? new RegExp(`^${pattern}$`)\n : new RegExp(`^${pattern}`);\n\n return regex.test(pathWithoutSearch);\n}\n\nexport function extractParamsFromPath(\n template: string,\n resolvedPath: string,\n): Record<string, string> {\n const pathWithoutSearch = resolvedPath.split(\"?\")[0] ?? \"\";\n const paramNames = extractParamNames(template);\n const regex = new RegExp(`^${createTemplatePattern(template)}$`);\n const match = pathWithoutSearch.match(regex);\n\n if (!match) return {};\n\n return Object.fromEntries(\n paramNames.map((name, index) => [name, match[index + 1] ?? \"\"]),\n );\n}\n\nexport function joinPaths(...segments: string[]): string {\n return (\n \"/\" +\n segments\n .map((segment) => segment.replace(/^\\/+|\\/+$/g, \"\"))\n .filter(Boolean)\n .join(\"/\")\n );\n}\n\nexport function build(\n template: string,\n params: RouteParams,\n query?: QueryParams,\n options?: BuildPathOptions,\n): string {\n return buildPath(template, params, query, options);\n}\n\nexport function getParamNames(template: string): string[] {\n return extractParamNames(template);\n}\n\n/**\n * Walk a `defineRoutes` output tree and return a flat array of\n * `{ key, path }` entries where `key` is the dot-joined key path from\n * the root (e.g. `\"SERVICES.BCC.EDIT\"`) and `path` is the raw template\n * string (e.g. `\"/services/bcc/edit/:id\"`).\n *\n * Useful for:\n * - Generating sitemaps from a single source of truth.\n * - Detecting duplicate path strings across branches at startup:\n *\n * @example\n * const flat = flattenRoutes(PATHS);\n * const paths = flat.map((r) => r.path);\n * const dupes = paths.filter((p, i) => paths.indexOf(p) !== i);\n * if (dupes.length) console.warn('Duplicate paths:', dupes);\n */\nexport function flattenRoutes(\n routes: Record<string, unknown>,\n prefix = \"\",\n): FlatRoute[] {\n const entries: FlatRoute[] = [];\n\n for (const key of Object.keys(routes)) {\n const fullKey = prefix ? `${prefix}.${key}` : key;\n const value = routes[key];\n\n if (typeof value === \"string\") {\n // Plain static string leaf.\n entries.push({ key: fullKey, path: value });\n } else if (value instanceof String) {\n // String-object leaf (wrapped dynamic path from defineRoutes).\n entries.push({ key: fullKey, path: value.valueOf() });\n } else if (typeof value === \"object\" && value !== null) {\n // Nested route group — recurse.\n entries.push(\n ...flattenRoutes(value as Record<string, unknown>, fullKey),\n );\n }\n // Anything else (functions, numbers, …) is silently skipped.\n }\n\n return entries;\n}\n\n","import { buildPath, extractParamNames, isDynamic } from \"./utils\";\nimport type {\n BuildPathOptions,\n ExtractParams,\n PathParams,\n QueryParams,\n RoutePath,\n} from \"../types\";\n\n// Re-export so consumers that import from 'core/defineRoutes' get the full surface\nexport { buildPath, extractParamNames, isDynamic } from \"./utils\";\n\ntype RouteInput = {\n [key: string]: string | RouteInput;\n};\n\ntype DynamicRoute<T extends string> = T extends `${string}:${string}`\n ? T & {\n build(params: PathParams<T>, query?: QueryParams, options?: BuildPathOptions): RoutePath;\n paramNames: Array<ExtractParams<T>>;\n }\n : T;\n\ntype ResolvedRoutes<T extends RouteInput> = {\n [K in keyof T]: T[K] extends RouteInput\n ? ResolvedRoutes<T[K]>\n : T[K] extends string\n ? DynamicRoute<T[K]>\n : never;\n};\n\nconst isRouteGroup = (value: unknown): value is RouteInput =>\n typeof value === \"object\" && value !== null;\n\nfunction wrapDynamicPath<T extends string>(template: T): DynamicRoute<T> {\n const paramNames = extractParamNames(template);\n const wrapped = new String(template) as unknown as DynamicRoute<T> & {\n build: (params: PathParams<T>, query?: QueryParams, options?: BuildPathOptions) => RoutePath;\n paramNames: Array<ExtractParams<T>>;\n };\n\n wrapped.build = (params: PathParams<T>, query?: QueryParams, options?: BuildPathOptions) =>\n buildPath(template, params, query, options) as RoutePath;\n wrapped.paramNames = paramNames as Array<ExtractParams<T>>;\n\n return wrapped as unknown as DynamicRoute<T>;\n}\n\nfunction processRouteMap<T extends RouteInput>(routes: T): ResolvedRoutes<T> {\n const result = {} as ResolvedRoutes<T>;\n\n for (const key in routes) {\n if (!Object.prototype.hasOwnProperty.call(routes, key)) continue;\n\n const value = routes[key];\n\n if (typeof value === \"string\") {\n result[key] = (\n isDynamic(value) ? wrapDynamicPath(value) : value\n ) as ResolvedRoutes<T>[typeof key];\n } else if (isRouteGroup(value)) {\n result[key] = processRouteMap(\n value as RouteInput,\n ) as unknown as ResolvedRoutes<T>[typeof key];\n }\n }\n\n return result;\n}\n\nexport function defineRoutes<T extends RouteInput>(\n routes: T,\n): ResolvedRoutes<T> {\n return processRouteMap(routes);\n}\n","/**\n * React integration hooks for route-forge.\n * These are thin wrappers — import only if you're using React Router.\n */\n\nimport { useParams, useNavigate, generatePath } from \"react-router-dom\";\nimport type {\n ExtractParams,\n QueryParams,\n RouteParams,\n BuildPathOptions,\n} from \"../types\";\nimport { appendQuery, extractParamNames, buildPath } from \"../core/utils\";\n\n// ─── useRouteParams ──────────────────────────────────────────────────────────\n\n/**\n * A typed wrapper around React Router's `useParams`.\n *\n * @example\n * ```tsx\n * // Route: '/a/:x/b/:y/c/:z'\n * const { x, y, z } = useRouteParams<'/a/:x/b/:y/c/:z'>();\n * ```\n */\nexport function useRouteParams<T extends string>(): Record<\n ExtractParams<T>,\n string\n> {\n return useParams() as Record<ExtractParams<T>, string>;\n}\n\n// ─── useNavigateTo ──────────────────────────────────────────────────────────\n\ntype NavigateOptions = {\n replace?: boolean;\n state?: unknown;\n};\n\n/**\n * A typed `navigate` helper that accepts a resolved path (output of `.build()`)\n * or a plain static path, with optional navigation options.\n *\n * @example\n * ```tsx\n * const navigateTo = useNavigateTo();\n * navigateTo(PATHS.USERS.EDIT.build({ id: 42 }));\n * navigateTo(PATHS.HOME, { replace: true });\n * ```\n */\nexport function useNavigateTo() {\n const navigate = useNavigate();\n\n return (path: string, options?: NavigateOptions) => {\n navigate(path, options);\n };\n}\n\n// ─── useResolvedPath ─────────────────────────────────────────────────────────\n\n/**\n * Resolves a dynamic path template against params using React Router's\n * `generatePath`, with proper typing.\n *\n * Accepts the same `options` bag as `build()` / `buildPath()`:\n * - (default) soft-fail: `console.warn` and return the partial path with unresolved `:param` placeholders.\n * - `{ strict: true }`: throw a `RangeError` on missing params — matching `.build()`'s strict behaviour.\n *\n * When all params are present, resolution is delegated to React Router's `generatePath`,\n * which correctly handles splat (`*`) and optional (`:param?`) segments.\n *\n * @example\n * ```tsx\n * const path = useResolvedPath('/users/:id', { id: 42 }); // → '/users/42'\n * const path = useResolvedPath('/users/:id', {}, undefined, { strict: true }); // throws RangeError\n * ```\n */\nexport function useResolvedPath(\n template: string,\n params: RouteParams,\n query?: QueryParams,\n options?: BuildPathOptions,\n): string {\n const paramNames = extractParamNames(template);\n const hasAllParams = paramNames.every(\n (name) => params[name] !== undefined && params[name] !== null,\n );\n\n if (!hasAllParams) {\n // Let buildPath own all missing-param behaviour (warn/throw) —\n // avoids re-implementing (and duplicating) the same check here.\n return buildPath(template, params, query, options);\n }\n\n // All params present — use generatePath for correct splat / optional-segment handling.\n const path = generatePath(\n template,\n Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)])),\n );\n\n return appendQuery(path, query);\n}\n"],"mappings":"AAGA,IAAMA,EAAgB,IAAM,YACtBC,EAAY,IAAM,sBAExB,SAASC,EAAYC,EAAuB,CAC1C,OAAOA,EAAM,QAAQF,EAAU,EAAG,MAAM,CAC1C,CAEA,SAASG,EAAsBC,EAA0B,CACvD,OAAOH,EAAYG,CAAQ,EAAE,QAAQL,EAAc,EAAG,SAAS,CACjE,CAEO,SAASM,EAAYC,EAAcC,EAA6B,CACrE,GAAI,CAACA,EAAO,OAAOD,EAEnB,IAAME,EAAe,IAAI,gBACzB,OAAW,CAACC,EAAKP,CAAK,IAAK,OAAO,QAAQK,CAAK,EAClBL,GAAU,OACjC,MAAM,QAAQA,CAAK,EACrBA,EAAM,QAASQ,GAAM,CACIA,GAAM,MAAMF,EAAa,OAAOC,EAAK,OAAO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N,EACA,OAAO,YAAY,OAAO,QAAQC,CAAM,EAAE,IAAI,CAAC,CAACM,EAAGC,CAAC,IAAM,CAACD,EAAG,OAAOC,CAAC,CAAC,CAAC,CAAC,CAC3E,EAEA,OAAOC,EAAYZ,EAAMK,CAAK,CAChC","names":["PATH_PARAM_RE","ESCAPE_RE","escapeRegex","value","createTemplatePattern","template","appendQuery","path","query","searchParams","key","v","queryString","buildPath","params","options","paramNames","extractParamNames","unresolved","name","resolved","replacement","p","match","isDynamic","isActivePath","currentPath","pathWithoutSearch","pattern","extractParamsFromPath","resolvedPath","regex","index","joinPaths","segments","segment","build","getParamNames","flattenRoutes","routes","prefix","entries","fullKey","isRouteGroup","value","wrapDynamicPath","template","paramNames","extractParamNames","wrapped","params","query","options","buildPath","processRouteMap","routes","result","key","isDynamic","defineRoutes","useParams","useNavigate","generatePath","useRouteParams","useParams","useNavigateTo","navigate","useNavigate","path","options","useResolvedPath","template","params","query","extractParamNames","name","buildPath","generatePath","k","v","appendQuery"]}
1
+ {"version":3,"sources":["../src/core/defineRoutes.ts"],"sourcesContent":["import {\n buildPath,\n devWarn,\n extractParamNames,\n flattenRoutes,\n isActivePath,\n isDynamic,\n} from \"./utils\";\nimport type {\n BuildPathOptions,\n ExtractParams,\n PathParams,\n QueryParams,\n RoutePath,\n RouteTree,\n} from \"../types\";\n\n// Re-export so consumers that import from 'core/defineRoutes' get the full surface\nexport { buildPath, extractParamNames, isDynamic } from \"./utils\";\n\n/**\n * A dynamic route is a template string with a `:param` or trailing `/*` splat,\n * augmented with a `.build()` helper and a `.paramNames` array.\n *\n * Exported so consumers (e.g. the hooks entry) can type against it.\n */\nexport type StaticRoute<T extends string> = T & {\n build(query?: QueryParams, options?: BuildPathOptions): RoutePath;\n};\n\nexport type DynamicRoute<T extends string> =\n T extends `${string}:${string}` | `${string}/*`\n ? T & {\n build(params: PathParams<T>, query?: QueryParams, options?: BuildPathOptions): RoutePath;\n paramNames: Array<ExtractParams<T>>;\n }\n : StaticRoute<T>;\n\ntype ResolvedRoutes<T extends RouteTree> = {\n [K in keyof T]: T[K] extends RouteTree\n ? ResolvedRoutes<T[K]>\n : T[K] extends string\n ? DynamicRoute<T[K]>\n : never;\n};\n\nconst isRouteGroup = (value: unknown): value is RouteTree =>\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) === Object.prototype;\n\n/**\n * Validate a single route template and warn (dev-only) about common mistakes:\n * missing leading `/` and non-trailing `*` splats.\n */\nfunction validateTemplate(template: string, key: string): void {\n if (!template.startsWith(\"/\")) {\n devWarn(\n `[route-forge] Route \"${key}\" does not start with \"/\": \"${template}\".`,\n );\n }\n\n if (template.includes(\"*\") && !template.endsWith(\"/*\")) {\n devWarn(\n `[route-forge] Route \"${key}\" uses \"*\" outside a trailing \"/*\" splat; only a trailing splat is supported: \"${template}\".`,\n );\n }\n}\n\n/**\n * Warn (dev-only) when two routes resolve to the same path template or shadow each other.\n */\nfunction detectDuplicatePaths(routes: Record<string, unknown>): void {\n const seen = new Map<string, string>();\n const warned = new Set<string>();\n const flat = flattenRoutes(routes);\n\n for (const route of flat) {\n const existing = seen.get(route.path);\n if (existing === undefined) {\n seen.set(route.path, route.key);\n } else if (!warned.has(route.path)) {\n warned.add(route.path);\n devWarn(\n `[route-forge] Duplicate route path \"${route.path}\" for \"${existing}\" and \"${route.key}\". ` +\n `Only one of them will be reachable.`,\n );\n }\n }\n\n // Shadowing check: warn when a static path matches a dynamic path defined before it\n for (let i = 0; i < flat.length; i++) {\n const r1 = flat[i]!;\n if (!isDynamic(r1.path)) continue;\n\n for (let j = i + 1; j < flat.length; j++) {\n const r2 = flat[j]!;\n if (isDynamic(r2.path)) continue;\n\n if (isActivePath(r2.path, r1.path, { exact: true })) {\n const pairKey = `${r1.key}->${r2.key}`;\n if (!warned.has(pairKey)) {\n warned.add(pairKey);\n devWarn(\n `[route-forge] Route \"${r2.key}\" (\"${r2.path}\") is shadowed by dynamic route \"${r1.key}\" (\"${r1.path}\"). Place static routes before dynamic parameters in route trees.`,\n );\n }\n }\n }\n }\n}\n\nfunction wrapStaticPath<T extends string>(template: T): StaticRoute<T> {\n const wrapped = new String(template) as unknown as StaticRoute<T> & {\n build: (query?: QueryParams, options?: BuildPathOptions) => RoutePath;\n };\n wrapped.build = (query?: QueryParams, options?: BuildPathOptions) =>\n buildPath(template, {}, query, options) as RoutePath;\n\n return wrapped as unknown as StaticRoute<T>;\n}\n\nfunction wrapDynamicPath<T extends string>(template: T): DynamicRoute<T> {\n const paramNames = extractParamNames(template);\n const wrapped = new String(template) as unknown as DynamicRoute<T> & {\n build: (params: PathParams<T>, query?: QueryParams, options?: BuildPathOptions) => RoutePath;\n paramNames: Array<ExtractParams<T>>;\n };\n\n wrapped.build = (params: PathParams<T>, query?: QueryParams, options?: BuildPathOptions) =>\n buildPath(template, params, query, options) as RoutePath;\n wrapped.paramNames = paramNames as Array<ExtractParams<T>>;\n\n return wrapped as unknown as DynamicRoute<T>;\n}\n\nfunction processRouteMap<T extends RouteTree>(routes: T): ResolvedRoutes<T> {\n const result = {} as ResolvedRoutes<T>;\n\n for (const key in routes) {\n if (!Object.prototype.hasOwnProperty.call(routes, key)) continue;\n\n const value = routes[key];\n\n if (typeof value === \"string\") {\n validateTemplate(value, key);\n result[key] = (\n isDynamic(value) ? wrapDynamicPath(value) : wrapStaticPath(value)\n ) as ResolvedRoutes<T>[typeof key];\n } else if (isRouteGroup(value)) {\n result[key] = processRouteMap(\n value as RouteTree,\n ) as unknown as ResolvedRoutes<T>[typeof key];\n }\n }\n\n return result;\n}\n\nexport function defineRoutes<T extends RouteTree>(\n routes: T,\n): ResolvedRoutes<T> {\n const result = processRouteMap(routes);\n detectDuplicatePaths(result as unknown as Record<string, unknown>);\n return result;\n}\n"],"mappings":"0IA8CA,IAAMA,EAAgBC,GACpB,OAAOA,GAAU,UACjBA,IAAU,MACV,CAAC,MAAM,QAAQA,CAAK,GACpB,OAAO,eAAeA,CAAK,IAAM,OAAO,UAM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OAAAmB,EAAQ,MAAQ,CAACC,EAAqBC,IACpCC,EAAUtB,EAAU,CAAC,EAAGoB,EAAOC,CAAO,EAEjCF,CACT,CAEA,SAASI,EAAkCvB,EAA8B,CACvE,IAAMwB,EAAaC,EAAkBzB,CAAQ,EACvCmB,EAAU,IAAI,OAAOnB,CAAQ,EAKnC,OAAAmB,EAAQ,MAAQ,CAACO,EAAuBN,EAAqBC,IAC3DC,EAAUtB,EAAU0B,EAAQN,EAAOC,CAAO,EAC5CF,EAAQ,WAAaK,EAEdL,CACT,CAEA,SAASQ,EAAqCvB,EAA8B,CAC1E,IAAMwB,EAAS,CAAC,EAEhB,QAAW3B,KAAOG,EAAQ,CACxB,GAAI,CAAC,OAAO,UAAU,eAAe,KAAKA,EAAQH,CAAG,EAAG,SAExD,IAAMH,EAAQM,EAAOH,CAAG,EAEpB,OAAOH,GAAU,UACnBC,EAAiBD,EAAOG,CAAG,EAC3B2B,EAAO3B,CAAG,EACRY,EAAUf,CAAK,EAAIyB,EAAgBzB,CAAK,EAAIoB,EAAepB,CAAK,GAEzDD,EAAaC,CAAK,IAC3B8B,EAAO3B,CAAG,EAAI0B,EACZ7B,CACF,EAEJ,CAEA,OAAO8B,CACT,CAEO,SAASC,EACdzB,EACmB,CACnB,IAAMwB,EAASD,EAAgBvB,CAAM,EACrC,OAAAD,EAAqByB,CAA4C,EAC1DA,CACT","names":["isRouteGroup","value","validateTemplate","template","key","devWarn","detectDuplicatePaths","routes","seen","warned","flat","flattenRoutes","route","existing","i","r1","isDynamic","j","r2","isActivePath","pairKey","wrapStaticPath","wrapped","query","options","buildPath","wrapDynamicPath","paramNames","extractParamNames","params","processRouteMap","result","defineRoutes"]}
package/package.json CHANGED
@@ -1,27 +1,66 @@
1
1
  {
2
2
  "name": "react-routes-forge",
3
- "version": "1.1.3",
4
- "description": "Type-safe route definitions with automatic path builders for React apps",
3
+ "version": "1.3.0",
4
+ "description": "Type-safe route definitions, automatic path builders, query parameter handling, and active route matching for React applications with zero duplication.",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "Mostafa Abdelhamid",
8
- "email": "mhsmustafa84@gmail.com"
8
+ "email": "mhsmustafa84@gmail.com",
9
+ "url": "https://github.com/mhsmustafa84"
9
10
  },
10
11
  "license": "MIT",
11
12
  "repository": {
12
13
  "type": "git",
13
- "url": "https://github.com/mhsmustafa84/react-routes-forge.git"
14
+ "url": "git+https://github.com/mhsmustafa84/react-routes-forge.git"
14
15
  },
15
- "homepage": "https://github.com/mhsmustafa84/react-routes-forge#readme",
16
- "bugs": "https://github.com/mhsmustafa84/react-routes-forge/issues",
16
+ "bugs": {
17
+ "url": "https://github.com/mhsmustafa84/react-routes-forge/issues"
18
+ },
19
+ "homepage": "https://mhsmustafa84.github.io/react-routes-forge",
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.cjs"
28
+ },
29
+ "./hooks": {
30
+ "types": "./dist/hooks/index.d.ts",
31
+ "import": "./dist/hooks/index.js",
32
+ "require": "./dist/hooks/index.cjs"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE"
40
+ ],
17
41
  "keywords": [
18
42
  "react",
19
43
  "router",
20
44
  "routes",
45
+ "routing",
21
46
  "typescript",
22
47
  "type-safe",
48
+ "typesafe",
49
+ "type-inference",
23
50
  "react-router",
24
- "path-builder"
51
+ "react-router-dom",
52
+ "path-builder",
53
+ "route-builder",
54
+ "typed-routes",
55
+ "url-builder",
56
+ "link-builder",
57
+ "navigation",
58
+ "query-params",
59
+ "search-params",
60
+ "url-params",
61
+ "deep-linking",
62
+ "spa",
63
+ "frontend"
25
64
  ],
26
65
  "publishConfig": {
27
66
  "access": "public"
@@ -30,27 +69,19 @@
30
69
  "node": ">=18.0.0"
31
70
  },
32
71
  "sideEffects": false,
33
- "exports": {
34
- ".": {
35
- "import": "./dist/index.js",
36
- "types": "./dist/index.d.ts"
37
- },
38
- "./package.json": "./package.json"
39
- },
40
- "types": "./dist/index.d.ts",
41
- "files": [
42
- "dist",
43
- "README.md",
44
- "LICENSE"
45
- ],
46
72
  "scripts": {
47
- "build": "tsup src/index.ts --format esm --dts --minify --sourcemap --clean",
73
+ "build": "tsup src/index.ts src/hooks/index.ts --format esm,cjs --dts --minify --sourcemap --clean",
48
74
  "lint": "tsc --noEmit",
75
+ "lint:eslint": "eslint . --ext .js,.cjs,.ts,.tsx",
49
76
  "test": "bun test",
50
77
  "test:watch": "bun test --watch",
78
+ "test:coverage": "vitest run --coverage",
51
79
  "prepare": "husky",
52
80
  "prepublishOnly": "bun run test && bun run build",
53
- "release": "standard-version"
81
+ "release": "standard-version",
82
+ "docs:dev": "vitepress dev docs",
83
+ "docs:build": "vitepress build docs",
84
+ "docs:preview": "vitepress preview docs"
54
85
  },
55
86
  "peerDependencies": {
56
87
  "react": ">=17",
@@ -64,17 +95,22 @@
64
95
  "devDependencies": {
65
96
  "@commitlint/cli": "^21.0.2",
66
97
  "@commitlint/config-conventional": "^21.0.2",
98
+ "@microsoft/eslint-formatter-sarif": "^3.1.0",
67
99
  "@testing-library/react": "^16.3.2",
68
- "@types/bun": "^1.3.14",
69
100
  "@types/jsdom": "^28.0.3",
70
101
  "@types/node": "^26.1.1",
71
102
  "@types/react": "^19.2.17",
103
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
104
+ "@typescript-eslint/parser": "^8.0.0",
105
+ "@vitest/coverage-v8": "^4.1.10",
106
+ "eslint": "^8.57.0",
72
107
  "husky": "^9.0.0",
73
108
  "jsdom": "^29.1.1",
74
109
  "react-router-dom": "^6.0.0",
75
110
  "standard-version": "^9.5.0",
76
111
  "tsup": "^8.0.0",
77
112
  "typescript": "^5.0.0",
113
+ "vitepress": "^1.6.4",
78
114
  "vitest": "^4.1.10"
79
115
  }
80
116
  }