@webtypen/webframez-core 0.3.16 → 0.3.17

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.
@@ -171,10 +171,29 @@ class RouterFacade {
171
171
  */
172
172
  extractParams(path, match) {
173
173
  const params = {};
174
- const paramNames = path.match(/\/:([\w]+)\??/g) || [];
174
+ const paramNames = path.match(/\/:(\[\w]+)\??/g) || [];
175
+ const wildcards = path.match(/\/\*\*|\/\*|\*\*/g) || [];
176
+ // Extract named parameters
175
177
  paramNames.forEach((param, index) => {
176
178
  params[param.substring(2).replace("?", "")] = match[index + 1] || null;
177
179
  });
180
+ // Extract wildcard parameters
181
+ let wildcardIndex = paramNames.length + 1;
182
+ wildcards.forEach((wildcard, index) => {
183
+ if (wildcard === '/**') {
184
+ params['wildcard'] = match[wildcardIndex] || '';
185
+ }
186
+ else if (wildcard === '/*') {
187
+ params['splat'] = match[wildcardIndex] || '';
188
+ }
189
+ else if (wildcard === '**') {
190
+ params['wildcard'] = match[wildcardIndex] || '';
191
+ }
192
+ else if (wildcard === '*') {
193
+ params['splat'] = match[wildcardIndex] || '';
194
+ }
195
+ wildcardIndex++;
196
+ });
178
197
  return params;
179
198
  }
180
199
  /**
@@ -195,6 +214,10 @@ class RouterFacade {
195
214
  routeObj.path
196
215
  .replace(/\/:\w+\?/g, "(?:/([^/]+))?")
197
216
  .replace(/\/:\w+/g, "/([^/]+)")
217
+ .replace(/\/\*\*/g, "/(.*)") // Catchall wildcard: /**
218
+ .replace(/\/\*/g, "/([^/]*)")
219
+ .replace(/\*\*/g, "(.*)")
220
+ .replace(/\*/g, "([^/]*)")
198
221
  .replace(/\//g, "\\/") +
199
222
  "$";
200
223
  const match = url.match(regex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.3.16",
3
+ "version": "0.3.17",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",
@@ -201,12 +201,29 @@ class RouterFacade {
201
201
  */
202
202
  extractParams(path: string, match: any) {
203
203
  const params: any = {};
204
- const paramNames = path.match(/\/:([\w]+)\??/g) || [];
204
+ const paramNames = path.match(/\/:(\[\w]+)\??/g) || [];
205
+ const wildcards = path.match(/\/\*\*|\/\*|\*\*/g) || [];
205
206
 
207
+ // Extract named parameters
206
208
  paramNames.forEach((param, index) => {
207
209
  params[param.substring(2).replace("?", "")] = match[index + 1] || null;
208
210
  });
209
211
 
212
+ // Extract wildcard parameters
213
+ let wildcardIndex = paramNames.length + 1;
214
+ wildcards.forEach((wildcard, index) => {
215
+ if (wildcard === '/**') {
216
+ params['wildcard'] = match[wildcardIndex] || '';
217
+ } else if (wildcard === '/*') {
218
+ params['splat'] = match[wildcardIndex] || '';
219
+ } else if (wildcard === '**') {
220
+ params['wildcard'] = match[wildcardIndex] || '';
221
+ } else if (wildcard === '*') {
222
+ params['splat'] = match[wildcardIndex] || '';
223
+ }
224
+ wildcardIndex++;
225
+ });
226
+
210
227
  return params;
211
228
  }
212
229
 
@@ -228,6 +245,10 @@ class RouterFacade {
228
245
  routeObj.path
229
246
  .replace(/\/:\w+\?/g, "(?:/([^/]+))?")
230
247
  .replace(/\/:\w+/g, "/([^/]+)")
248
+ .replace(/\/\*\*/g, "/(.*)") // Catchall wildcard: /**
249
+ .replace(/\/\*/g, "/([^/]*)")
250
+ .replace(/\*\*/g, "(.*)")
251
+ .replace(/\*/g, "([^/]*)")
231
252
  .replace(/\//g, "\\/") +
232
253
  "$";
233
254
  const match = url.match(regex);