@@ -150,12 +150,6 @@ export function defineParamParser<TOut, TIn extends string | string[]>(parser: {
150150 return parser
151151}
152152
153- interface IdFn {
154- ( v : undefined | null ) : null
155- ( v : string ) : string
156- ( v : string [ ] ) : string [ ]
157- }
158-
159153const PATH_PARAM_DEFAULT_GET = ( value : string | string [ ] | null | undefined ) =>
160154 value ?? null
161155export const PATH_PARAM_SINGLE_DEFAULT : Param_GetSet < string , string > = { }
@@ -344,52 +338,6 @@ export class MatcherPatternPathCustomParams<
344338 }
345339}
346340
347- const aaa = new MatcherPatternPathCustomParams (
348- / ^ \/ p r o f i l e s \/ ( [ ^ / ] + ) $ / i,
349- {
350- userId : {
351- parser : PARAM_INTEGER ,
352- // parser: PATH_PARAM_DEFAULT_PARSER,
353- } ,
354- } ,
355- [ 'profiles' , 0 ]
356- )
357- // @ts -expect-error: not existing param
358- aaa . build ( { a : '2' } )
359- // @ts -expect-error: must be a number
360- aaa . build ( { userId : '2' } )
361- aaa . build ( { userId : 2 } )
362- // @ts -expect-error: not existing param
363- aaa . match ( '/profiles/2' ) ?. e
364- // @ts -expect-error: not existing param
365- aaa . match ( '/profiles/2' ) . e
366- aaa . match ( '/profiles/2' ) . userId . toFixed ( 2 )
367-
368- // Factory function for better type inference
369- export function createMatcherPatternPathCustomParams <
370- TParamsOptions extends Record <
371- string ,
372- MatcherPatternPathCustomParamOptions < any , any >
373- > ,
374- > (
375- re : RegExp ,
376- params : TParamsOptions ,
377- pathParts : Array < string | number >
378- ) : MatcherPatternPathCustomParams < TParamsOptions > {
379- return new MatcherPatternPathCustomParams ( re , params , pathParts )
380- }
381-
382- // Now use it like this:
383- const aab = createMatcherPatternPathCustomParams (
384- / ^ \/ p r o f i l e s \/ ( [ ^ / ] + ) $ / i,
385- {
386- userId : {
387- parser : PARAM_INTEGER ,
388- } ,
389- } ,
390- [ 'profiles' , 0 ]
391- )
392-
393341/**
394342 * Matcher for dynamic paths, e.g. `/team/:id/:name`.
395343 * Supports one, one or zero, one or more and zero or more params.
0 commit comments