@b9g/match-pattern 0.1.2 → 0.1.4
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/package.json +16 -16
- package/src/match-pattern.d.ts +2 -2
- package/src/match-pattern.js +9 -40
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -6
package/package.json
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/match-pattern",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@b9g/libuild": "^0.1.10"
|
|
6
6
|
},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"urlpattern-polyfill": "^10.0.0"
|
|
9
|
+
},
|
|
10
|
+
"peerDependenciesMeta": {
|
|
11
|
+
"urlpattern-polyfill": {
|
|
12
|
+
"optional": true
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"type": "module",
|
|
8
|
-
"types": "src/
|
|
9
|
-
"module": "src/
|
|
16
|
+
"types": "src/match-pattern.d.ts",
|
|
17
|
+
"module": "src/match-pattern.js",
|
|
10
18
|
"exports": {
|
|
11
|
-
".": {
|
|
12
|
-
"types": "./src/index.d.ts",
|
|
13
|
-
"import": "./src/index.js"
|
|
14
|
-
},
|
|
15
|
-
"./index": {
|
|
16
|
-
"types": "./src/index.d.ts",
|
|
17
|
-
"import": "./src/index.js"
|
|
18
|
-
},
|
|
19
|
-
"./index.js": {
|
|
20
|
-
"types": "./src/index.d.ts",
|
|
21
|
-
"import": "./src/index.js"
|
|
22
|
-
},
|
|
23
19
|
"./match-pattern": {
|
|
24
20
|
"types": "./src/match-pattern.d.ts",
|
|
25
21
|
"import": "./src/match-pattern.js"
|
|
@@ -28,6 +24,10 @@
|
|
|
28
24
|
"types": "./src/match-pattern.d.ts",
|
|
29
25
|
"import": "./src/match-pattern.js"
|
|
30
26
|
},
|
|
31
|
-
"./package.json": "./package.json"
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./src/match-pattern.d.ts",
|
|
30
|
+
"import": "./src/match-pattern.js"
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/match-pattern.d.ts
CHANGED
|
@@ -32,11 +32,11 @@ export declare class MatchPattern extends URLPattern {
|
|
|
32
32
|
private _originalInput;
|
|
33
33
|
constructor(input: string | URLPatternInit, baseURL?: string);
|
|
34
34
|
/**
|
|
35
|
-
* Enhanced exec that returns unified params object
|
|
35
|
+
* Enhanced exec that returns unified params object
|
|
36
36
|
*/
|
|
37
37
|
exec(input: string | URL): MatchPatternResult | null;
|
|
38
38
|
/**
|
|
39
|
-
* Enhanced test with order-independent search parameter matching
|
|
39
|
+
* Enhanced test with order-independent search parameter matching
|
|
40
40
|
*/
|
|
41
41
|
test(input: string | URL): boolean;
|
|
42
42
|
}
|
package/src/match-pattern.js
CHANGED
|
@@ -12,47 +12,41 @@ var MatchPattern = class extends URLPattern {
|
|
|
12
12
|
if (typeof input === "string") {
|
|
13
13
|
processedInput = parseStringPattern(input);
|
|
14
14
|
}
|
|
15
|
-
const normalizedInput = normalizePatternTrailingSlash(processedInput);
|
|
16
15
|
if (baseURL !== void 0) {
|
|
17
|
-
super(
|
|
16
|
+
super(processedInput, baseURL);
|
|
18
17
|
} else {
|
|
19
|
-
super(
|
|
18
|
+
super(processedInput);
|
|
20
19
|
}
|
|
21
|
-
this._originalInput =
|
|
20
|
+
this._originalInput = processedInput;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
|
-
* Enhanced exec that returns unified params object
|
|
23
|
+
* Enhanced exec that returns unified params object
|
|
25
24
|
*/
|
|
26
25
|
exec(input) {
|
|
27
26
|
if (!this.test(input)) {
|
|
28
27
|
return null;
|
|
29
28
|
}
|
|
30
|
-
const
|
|
31
|
-
const normalizedUrl = normalizeTrailingSlash(url);
|
|
32
|
-
const result = super.exec(normalizedUrl);
|
|
29
|
+
const result = super.exec(input);
|
|
33
30
|
if (result) {
|
|
34
31
|
const enhancedResult = {
|
|
35
32
|
...result,
|
|
36
33
|
params: extractUnifiedParams(result, input)
|
|
37
|
-
// Use original input for search params
|
|
38
34
|
};
|
|
39
35
|
return enhancedResult;
|
|
40
36
|
}
|
|
41
37
|
return buildCustomResult(this, input);
|
|
42
38
|
}
|
|
43
39
|
/**
|
|
44
|
-
* Enhanced test with order-independent search parameter matching
|
|
40
|
+
* Enhanced test with order-independent search parameter matching
|
|
45
41
|
*/
|
|
46
42
|
test(input) {
|
|
47
43
|
const url = typeof input === "string" ? new URL(input) : input;
|
|
48
|
-
const normalizedUrl = normalizeTrailingSlash(url);
|
|
49
44
|
if (!this.search || this.search === "*") {
|
|
50
|
-
return super.test(
|
|
45
|
+
return super.test(input);
|
|
51
46
|
}
|
|
52
47
|
const pathPatternInit = typeof this._originalInput === "string" ? { pathname: this._originalInput } : { ...this._originalInput, search: void 0 };
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
if (!pathPattern.test(normalizedUrl)) {
|
|
48
|
+
const pathPattern = new URLPattern(pathPatternInit);
|
|
49
|
+
if (!pathPattern.test(input)) {
|
|
56
50
|
return false;
|
|
57
51
|
}
|
|
58
52
|
return testSearchParameters(this.search, url.searchParams);
|
|
@@ -113,31 +107,6 @@ function extractUnifiedParams(result, url) {
|
|
|
113
107
|
}
|
|
114
108
|
return params;
|
|
115
109
|
}
|
|
116
|
-
function normalizeTrailingSlash(url) {
|
|
117
|
-
const normalized = new URL(url.href);
|
|
118
|
-
if (normalized.pathname === "/") {
|
|
119
|
-
return normalized;
|
|
120
|
-
}
|
|
121
|
-
if (normalized.pathname.endsWith("/")) {
|
|
122
|
-
normalized.pathname = normalized.pathname.slice(0, -1);
|
|
123
|
-
}
|
|
124
|
-
return normalized;
|
|
125
|
-
}
|
|
126
|
-
function normalizePatternTrailingSlash(patternInit) {
|
|
127
|
-
if (typeof patternInit === "string") {
|
|
128
|
-
if (patternInit === "/" || patternInit === "") {
|
|
129
|
-
return patternInit;
|
|
130
|
-
}
|
|
131
|
-
return patternInit.endsWith("/") ? patternInit.slice(0, -1) : patternInit;
|
|
132
|
-
}
|
|
133
|
-
const normalized = { ...patternInit };
|
|
134
|
-
if (normalized.pathname && normalized.pathname !== "/") {
|
|
135
|
-
if (normalized.pathname.endsWith("/")) {
|
|
136
|
-
normalized.pathname = normalized.pathname.slice(0, -1);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return normalized;
|
|
140
|
-
}
|
|
141
110
|
function buildCustomResult(pattern, input) {
|
|
142
111
|
const url = typeof input === "string" ? new URL(input) : input;
|
|
143
112
|
const result = {
|
package/src/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { MatchPattern, type MatchPatternResult } from "./match-pattern.ts";
|