litestar-vite-plugin 0.6.4 → 0.6.5

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.
@@ -94,27 +94,28 @@ export function currentRoute() {
94
94
  export function isRoute(url, routeName) {
95
95
  url = getRelativeUrlPath(url);
96
96
  url = url === '/' ? url : url.replace(/\/$/, '');
97
- try {
98
- const routePattern = routes[routeName];
99
- const regexPattern = routePattern.replace(/\//g, '\\/').replace(/\{([^}]+):([^}]+)\}/g, (match, paramName, paramType) => {
100
- // Create a regex pattern based on the parameter type
101
- switch (paramType) {
102
- case 'str':
103
- case 'path':
104
- return '([^/]+)'; // Match any non-slash characters
105
- case 'uuid':
106
- return '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'; // Match a UUID pattern
107
- default:
108
- return '([^/]+)'; // Default to match any non-slash characters
97
+ const routeNameRegex = new RegExp('^' + routeName.replace(/\*/g, '.*') + '$');
98
+ for (const routeName in routes) {
99
+ if (routeNameRegex.test(routeName)) {
100
+ const routePattern = routes[routeName];
101
+ const regexPattern = routePattern.replace(/\//g, '\\/').replace(/\{([^}]+):([^}]+)\}/g, (match, paramName, paramType) => {
102
+ switch (paramType) {
103
+ case 'str':
104
+ case 'path':
105
+ return '([^/]+)';
106
+ case 'uuid':
107
+ return '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
108
+ default:
109
+ return '([^/]+)';
110
+ }
111
+ });
112
+ const regex = new RegExp(`^${regexPattern}$`);
113
+ if (regex.test(url)) {
114
+ return true;
109
115
  }
110
- });
111
- const regex = new RegExp(`^${regexPattern}$`);
112
- return regex.test(url);
113
- }
114
- catch (error) {
115
- console.error(error);
116
- return false;
116
+ }
117
117
  }
118
+ return false;
118
119
  }
119
120
  export function isCurrentRoute(routeName) {
120
121
  const currentRouteName = currentRoute();
@@ -122,7 +123,8 @@ export function isCurrentRoute(routeName) {
122
123
  console.error("Could not match current window location to a named route.");
123
124
  return false;
124
125
  }
125
- return currentRouteName == routeName;
126
+ const routeNameRegex = new RegExp('^' + routeName.replace(/\*/g, '.*') + '$');
127
+ return routeNameRegex.test(currentRouteName);
126
128
  }
127
129
  globalThis.routes = globalThis.routes || {};
128
130
  globalThis.route = route;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litestar-vite-plugin",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "type": "module",
5
5
  "description": "Litestar plugin for Vite.",
6
6
  "keywords": [