Skip to content

Commit f1aa2db

Browse files
committed
chore: format
1 parent 578cc0b commit f1aa2db

File tree

3 files changed

+51
-50
lines changed

3 files changed

+51
-50
lines changed

docs/hooks/use-match.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ title: useMatch
88
<summary>Type declaration</summary>
99

1010
```tsx
11-
declare function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(
11+
declare function useMatch<
12+
ParamKey extends ParamParseKey<Path>,
13+
Path extends string
14+
>(
1215
pattern: PathPattern<Path> | Path
1316
): PathMatch<ParamKey> | null;
1417
```

docs/utils/generate-path.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,23 @@ title: generatePath
88
<summary>Type declaration</summary>
99

1010
```tsx
11-
type PathParams<
12-
Path extends string
13-
> = Path extends `:${infer Param}/${infer Rest}`
14-
? Param | PathParams<Rest>
15-
: Path extends `:${infer Param}`
16-
? Param
17-
: Path extends `${any}:${infer Param}`
18-
? PathParams<`:${Param}`>
19-
: Path extends `${any}/*`
20-
? "*"
21-
: Path extends "*"
22-
? "*"
23-
: never
24-
11+
type PathParams<Path extends string> =
12+
Path extends `:${infer Param}/${infer Rest}`
13+
? Param | PathParams<Rest>
14+
: Path extends `:${infer Param}`
15+
? Param
16+
: Path extends `${any}:${infer Param}`
17+
? PathParams<`:${Param}`>
18+
: Path extends `${any}/*`
19+
? "*"
20+
: Path extends "*"
21+
? "*"
22+
: never;
2523

2624
declare function generatePath<Path extends string>(
2725
path: Path,
2826
params?: {
29-
[key in PathParams<Path>]: string
27+
[key in PathParams<Path>]: string;
3028
}
3129
): string;
3230
```

packages/router/utils.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -161,41 +161,40 @@ export interface DataRouteObject extends RouteObject {
161161
id: string;
162162
}
163163

164-
type Star = "*"
164+
type Star = "*";
165165
/**
166166
* @private
167167
* Return string union from path string.
168168
* @example
169169
* PathParam<"/path/:a/:b"> // "a" | "b"
170170
* PathParam<"/path/:a/:b/*"> // "a" | "b" | "*"
171171
*/
172-
type PathParam<
173-
Path extends string
174-
> =
175-
// Check path string starts with slash and a param string.
176-
Path extends `:${infer Param}/${infer Rest}`
177-
? Param | PathParam<Rest>
178-
// Check path string is a param string.
179-
: Path extends `:${infer Param}`
180-
? Param
181-
// Check path string ends with slash and a param string.
182-
: Path extends `${any}/:${infer Param}`
183-
? PathParam<`:${Param}`>
184-
// Check path string ends with slash and a star.
185-
: Path extends `${any}/${Star}`
186-
? Star
187-
// Check string is star.
188-
: Path extends Star
189-
? Star
190-
: never
172+
type PathParam<Path extends string> =
173+
// Check path string starts with slash and a param string.
174+
Path extends `:${infer Param}/${infer Rest}`
175+
? Param | PathParam<Rest>
176+
: // Check path string is a param string.
177+
Path extends `:${infer Param}`
178+
? Param
179+
: // Check path string ends with slash and a param string.
180+
Path extends `${any}/:${infer Param}`
181+
? PathParam<`:${Param}`>
182+
: // Check path string ends with slash and a star.
183+
Path extends `${any}/${Star}`
184+
? Star
185+
: // Check string is star.
186+
Path extends Star
187+
? Star
188+
: never;
191189

192190
// Attempt to parse the given string segment. If it fails, then just return the
193191
// plain string type as a default fallback. Otherwise return the union of the
194192
// parsed string literals that were referenced as dynamic segments in the route.
195-
export type ParamParseKey<Segment extends string> =
196-
[PathParam<Segment>] extends [never]
197-
? PathParam<Segment>
198-
: string;
193+
export type ParamParseKey<Segment extends string> = [
194+
PathParam<Segment>
195+
] extends [never]
196+
? PathParam<Segment>
197+
: string;
199198

200199
/**
201200
* The parameters that were parsed from the URL path.
@@ -464,21 +463,22 @@ function matchRouteBranch<
464463
*
465464
* @see https://reactrouter.com/docs/en/v6/utils/generate-path
466465
*/
467-
export function generatePath<Path extends string>(path: Path, params: {
468-
[key in PathParam<Path>]: string
469-
} = {} as any): string {
466+
export function generatePath<Path extends string>(
467+
path: Path,
468+
params: {
469+
[key in PathParam<Path>]: string;
470+
} = {} as any
471+
): string {
470472
return path
471473
.replace(/:(\w+)/g, (_, key: PathParam<Path>) => {
472474
invariant(params[key] != null, `Missing ":${key}" param`);
473475
return params[key]!;
474476
})
475-
.replace(/\/*\*$/, (_) =>
476-
{
477-
const star = "*" as PathParam<Path>
478-
479-
return params[star] == null ? "" : params[star].replace(/^\/*/, "/")
480-
}
481-
);
477+
.replace(/\/*\*$/, (_) => {
478+
const star = "*" as PathParam<Path>;
479+
480+
return params[star] == null ? "" : params[star].replace(/^\/*/, "/");
481+
});
482482
}
483483

484484
/**

0 commit comments

Comments
 (0)