@pirxpilot/router 2.0.0 → 2.0.2
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 PARAMETER_REGEXP = /\/:([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 = pathname.matchAll(PARAMETER_REGEXP).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,6 +75,20 @@ 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
|
+
// mark as processed
|
|
87
|
+
match.pathname.groups[key] = undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Also handle any additional groups not in parameterOrder (e.g., numbered groups)
|
|
73
92
|
for (const [key, value] of Object.entries(match.pathname.groups)) {
|
|
74
93
|
// Skip the default wildcard capture group '0'
|
|
75
94
|
if (key === '0') continue;
|
package/package.json
CHANGED