@pirxpilot/router 2.0.0 → 2.0.1
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.
- package/lib/matcher.js +19 -0
- package/package.json +1 -1
package/lib/matcher.js
CHANGED
|
@@ -47,7 +47,12 @@ export function createRegexMatcher(path) {
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
const parameterRegex = /:([a-zA-Z_]\w*)/g;
|
|
51
|
+
|
|
50
52
|
export function createURLPatternMatcher(pathname, { sensitive, end, strict }) {
|
|
53
|
+
// Extract parameter names from the pattern in order
|
|
54
|
+
const parameterOrder = new Set(pathname.matchAll(parameterRegex).map(m => m[1]));
|
|
55
|
+
|
|
51
56
|
// Build the pattern:
|
|
52
57
|
// - For end=false (prefix matching): add {/*}? to match optional trailing content
|
|
53
58
|
// - For end=true with trailing=true: add {/}? to match optional trailing slash
|
|
@@ -70,9 +75,23 @@ export function createURLPatternMatcher(pathname, { sensitive, end, strict }) {
|
|
|
70
75
|
|
|
71
76
|
const params = {};
|
|
72
77
|
const keys = [];
|
|
78
|
+
|
|
79
|
+
// Process parameters in the order they appear in the pattern
|
|
80
|
+
// Use the preserved parameter order
|
|
81
|
+
for (const key of parameterOrder) {
|
|
82
|
+
const value = match.pathname.groups[key];
|
|
83
|
+
if (value !== undefined) {
|
|
84
|
+
keys.push(key);
|
|
85
|
+
params[key] = decodeParam(value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Also handle any additional groups not in parameterOrder (e.g., numbered groups)
|
|
73
90
|
for (const [key, value] of Object.entries(match.pathname.groups)) {
|
|
74
91
|
// Skip the default wildcard capture group '0'
|
|
75
92
|
if (key === '0') continue;
|
|
93
|
+
// Skip if we already processed this key
|
|
94
|
+
if (parameterOrder.has(key)) continue;
|
|
76
95
|
if (value !== undefined) {
|
|
77
96
|
keys.push(key);
|
|
78
97
|
params[key] = decodeParam(value);
|
package/package.json
CHANGED