@@ -11,39 +11,50 @@ export class LegacyRouteConverter {
1111   * path-to-regexp used by Express>=v5 and @fastify/middie>=v9 no longer support unnamed wildcards. 
1212   * This method attempts to convert the old syntax to the new one, and logs an error if it fails. 
1313   * @param  route The route to convert. 
14+    * @param  options Options object. 
1415   * @returns  The converted route, or the original route if it cannot be converted. 
1516   */ 
16-   static  tryConvert ( route : string ) : string  { 
17+   static  tryConvert ( 
18+     route : string , 
19+     options ?: { 
20+       logs ?: boolean ; 
21+     } , 
22+   ) : string  { 
1723    // Normalize path to eliminate additional if statements. 
1824    const  routeWithLeadingSlash  =  route . startsWith ( '/' )  ? route  : `/${ route }  ` ; 
1925    const  normalizedRoute  =  route . endsWith ( '/' ) 
2026      ? routeWithLeadingSlash 
2127      : `${ routeWithLeadingSlash }  /` ; 
2228
29+     const  loggingEnabled  =  options ?. logs  ??  true ; 
30+     const  printWarning  =  loggingEnabled 
31+       ? this . printWarning . bind ( this ) 
32+       : ( )  =>  { } ; 
33+ 
2334    if  ( normalizedRoute . endsWith ( '/(.*)/' ) )  { 
2435      // Skip printing warning for the "all" wildcard. 
2536      if  ( normalizedRoute  !==  '/(.*)/' )  { 
26-         this . printWarning ( route ) ; 
37+         printWarning ( route ) ; 
2738      } 
2839      return  route . replace ( '(.*)' ,  '{*path}' ) ; 
2940    } 
3041
3142    if  ( normalizedRoute . endsWith ( '/*/' ) )  { 
3243      // Skip printing warning for the "all" wildcard. 
3344      if  ( normalizedRoute  !==  '/*/' )  { 
34-         this . printWarning ( route ) ; 
45+         printWarning ( route ) ; 
3546      } 
3647      return  route . replace ( '*' ,  '{*path}' ) ; 
3748    } 
3849
3950    if  ( normalizedRoute . endsWith ( '/+/' ) )  { 
40-       this . printWarning ( route ) ; 
51+       printWarning ( route ) ; 
4152      return  route . replace ( '/+' ,  '/*path' ) ; 
4253    } 
4354
4455    // When route includes any wildcard segments in the middle. 
4556    if  ( normalizedRoute . includes ( '/*/' ) )  { 
46-       this . printWarning ( route ) ; 
57+       printWarning ( route ) ; 
4758      // Replace each /*/ segment with a named parameter using different name for each segment. 
4859      return  route . replaceAll ( '/*/' ,  ( match ,  offset )  =>  { 
4960        return  `/*path${ offset }  /` ; 
0 commit comments