File tree Expand file tree Collapse file tree 5 files changed +82
-0
lines changed
Expand file tree Collapse file tree 5 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ *
2+ ! ** /* .d.ts
3+ ! ** /* .d.cts
4+ ! ** /* .d.mts
5+ ! ** /* .d. * .ts
Original file line number Diff line number Diff line change 1+ export interface StringRoute {
2+ parse : ( url : string ) => Record < string , string > | null ;
3+ stringify : ( params : Record < string , string > ) => string ;
4+ }
5+
6+ export interface RegExpRoute {
7+ parse : ( url : string ) => { captures : Array < string | undefined > } | null ;
8+ }
9+
10+ export type StringRouteRule = RegExp | ( ( value : string ) => boolean ) ;
11+ export type StringRouteRules = Record < string , StringRouteRule > ;
12+
13+ export function routeMatcher ( route : string , rules ?: StringRouteRules ) : StringRoute ;
14+ export function routeMatcher ( route : RegExp ) : RegExpRoute ;
Original file line number Diff line number Diff line change 1+ {
2+ "private" : true ,
3+ "name" : " @types/route-matcher" ,
4+ "version" : " 0.1.9999" ,
5+ "projects" : [
6+ " https://github.com/cowboy/javascript-route-matcher"
7+ ],
8+ "devDependencies" : {
9+ "@types/route-matcher" : " workspace:."
10+ },
11+ "owners" : [
12+ {
13+ "name" : " mchevestrier" ,
14+ "githubUsername" : " mchevestrier"
15+ }
16+ ]
17+ }
Original file line number Diff line number Diff line change 1+ import { routeMatcher } from "route-matcher" ;
2+
3+ // $ExpectType StringRoute
4+ const search = routeMatcher ( "search/:query/p:page" ) ;
5+
6+ // $ExpectType Record<string, string> | null
7+ search . parse ( "search/cowboy/p5" ) ;
8+
9+ // $ExpectType StringRoute
10+ const user = routeMatcher ( "user/:id/:other" , {
11+ id : / ^ \d + $ / ,
12+ other : function ( value ) {
13+ return value === "" || value === "foo" ;
14+ } ,
15+ } ) ;
16+
17+ // $ExpectType string
18+ user . stringify ( { id : "abc" , other : "xyz" } ) ;
19+
20+ // $ExpectType RegExpRoute
21+ const users = routeMatcher ( / ^ ( u s e r s ? ) (?: \/ ( \d + ) (?: \. \. ( \d + ) ) ? ) ? / ) ;
22+
23+ // $ExpectType { captures: (string | undefined)[]; } | null
24+ users . parse ( "user/123" ) ;
25+
26+ // @ts -expect-error - stringification isn't supported for RegExp routes
27+ users . stringify ( { id : "abc" , other : "xyz" } ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "module" : " node16" ,
4+ "lib" : [
5+ " es6"
6+ ],
7+ "noImplicitAny" : true ,
8+ "noImplicitThis" : true ,
9+ "strictFunctionTypes" : true ,
10+ "strictNullChecks" : true ,
11+ "types" : [],
12+ "noEmit" : true ,
13+ "forceConsistentCasingInFileNames" : true
14+ },
15+ "files" : [
16+ " index.d.ts" ,
17+ " route-matcher-tests.ts"
18+ ]
19+ }
You can’t perform that action at this time.
0 commit comments