@rolldown/pluginutils 1.0.0-beta.8-commit.985af6d → 1.0.0-beta.8-commit.bf53a10
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/dist/index.cjs +12 -10
- package/dist/index.d.cts +2 -7
- package/dist/index.d.ts +2 -7
- package/dist/index.js +11 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,13 @@ const postfixRE = /[?#].*$/;
|
|
|
5
5
|
function cleanUrl(url) {
|
|
6
6
|
return url.replace(postfixRE, "");
|
|
7
7
|
}
|
|
8
|
+
function extractQueryWithoutFragment(url) {
|
|
9
|
+
const questionMarkIndex = url.indexOf("?");
|
|
10
|
+
if (questionMarkIndex === -1) return "";
|
|
11
|
+
const fragmentIndex = url.indexOf("#", questionMarkIndex);
|
|
12
|
+
if (fragmentIndex === -1) return url.substring(questionMarkIndex);
|
|
13
|
+
else return url.substring(questionMarkIndex, fragmentIndex);
|
|
14
|
+
}
|
|
8
15
|
|
|
9
16
|
//#endregion
|
|
10
17
|
//#region src/composable-filters.ts
|
|
@@ -120,13 +127,8 @@ function exclude(expr) {
|
|
|
120
127
|
* ```
|
|
121
128
|
* @param queryFilterObject The query filter object needs to be matched.
|
|
122
129
|
* @returns a `And` FilterExpression
|
|
123
|
-
*
|
|
124
|
-
* There are three kinds of conditions are supported:
|
|
125
|
-
* 1. `boolean`: if the value is `true`, the key must exist and be truthy. if the value is `false`, the key must not exist or be falsy.
|
|
126
|
-
* 2. `string`: the key must exist and be equal to the value.
|
|
127
|
-
* 3. `RegExp`: the key must exist and match the value.
|
|
128
130
|
*/
|
|
129
|
-
function
|
|
131
|
+
function queries(queryFilter) {
|
|
130
132
|
let arr = Object.entries(queryFilter).map(([key, value]) => {
|
|
131
133
|
return new Query(key, value);
|
|
132
134
|
});
|
|
@@ -174,7 +176,7 @@ function exprInterpreter(expr, code$1, id$1, moduleType$1, ctx = {}) {
|
|
|
174
176
|
case "query": {
|
|
175
177
|
if (id$1 === void 0) throw new Error("`id` is required for `Query` expression");
|
|
176
178
|
if (!ctx.urlSearchParamsCache) {
|
|
177
|
-
let
|
|
179
|
+
let queryString = extractQueryWithoutFragment(id$1);
|
|
178
180
|
ctx.urlSearchParamsCache = new URLSearchParams(queryString);
|
|
179
181
|
}
|
|
180
182
|
let urlParams = ctx.urlSearchParamsCache;
|
|
@@ -183,7 +185,7 @@ function exprInterpreter(expr, code$1, id$1, moduleType$1, ctx = {}) {
|
|
|
183
185
|
else if (typeof expr.pattern === "string") return urlParams.get(expr.key) === expr.pattern;
|
|
184
186
|
else return expr.pattern.test(urlParams.get(expr.key) ?? "");
|
|
185
187
|
}
|
|
186
|
-
default: throw new Error(`Expression
|
|
188
|
+
default: throw new Error(`Expression ${JSON.stringify(expr)} is not expected.`);
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
191
|
|
|
@@ -250,5 +252,5 @@ exports.moduleType = moduleType
|
|
|
250
252
|
exports.not = not
|
|
251
253
|
exports.or = or
|
|
252
254
|
exports.prefixRegex = prefixRegex
|
|
253
|
-
exports.
|
|
254
|
-
exports.
|
|
255
|
+
exports.queries = queries
|
|
256
|
+
exports.query = query
|
package/dist/index.d.cts
CHANGED
|
@@ -73,13 +73,8 @@ declare function exclude(expr: FilterExpression): Exclude;
|
|
|
73
73
|
* ```
|
|
74
74
|
* @param queryFilterObject The query filter object needs to be matched.
|
|
75
75
|
* @returns a `And` FilterExpression
|
|
76
|
-
*
|
|
77
|
-
* There are three kinds of conditions are supported:
|
|
78
|
-
* 1. `boolean`: if the value is `true`, the key must exist and be truthy. if the value is `false`, the key must not exist or be falsy.
|
|
79
|
-
* 2. `string`: the key must exist and be equal to the value.
|
|
80
|
-
* 3. `RegExp`: the key must exist and match the value.
|
|
81
76
|
*/
|
|
82
|
-
declare function
|
|
77
|
+
declare function queries(queryFilter: QueryFilterObject): And;
|
|
83
78
|
declare function interpreter(exprs: TopLevelFilterExpression | TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType): boolean;
|
|
84
79
|
interface InterpreterCtx {
|
|
85
80
|
urlSearchParamsCache?: URLSearchParams;
|
|
@@ -118,4 +113,4 @@ declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input:
|
|
|
118
113
|
declare function makeIdFiltersToMatchWithQuery(input: string | RegExp | readonly (string | RegExp)[]): string | RegExp | (string | RegExp)[];
|
|
119
114
|
|
|
120
115
|
//#endregion
|
|
121
|
-
export { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex,
|
|
116
|
+
export { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query };
|
package/dist/index.d.ts
CHANGED
|
@@ -73,13 +73,8 @@ declare function exclude(expr: FilterExpression): Exclude;
|
|
|
73
73
|
* ```
|
|
74
74
|
* @param queryFilterObject The query filter object needs to be matched.
|
|
75
75
|
* @returns a `And` FilterExpression
|
|
76
|
-
*
|
|
77
|
-
* There are three kinds of conditions are supported:
|
|
78
|
-
* 1. `boolean`: if the value is `true`, the key must exist and be truthy. if the value is `false`, the key must not exist or be falsy.
|
|
79
|
-
* 2. `string`: the key must exist and be equal to the value.
|
|
80
|
-
* 3. `RegExp`: the key must exist and match the value.
|
|
81
76
|
*/
|
|
82
|
-
declare function
|
|
77
|
+
declare function queries(queryFilter: QueryFilterObject): And;
|
|
83
78
|
declare function interpreter(exprs: TopLevelFilterExpression | TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType): boolean;
|
|
84
79
|
interface InterpreterCtx {
|
|
85
80
|
urlSearchParamsCache?: URLSearchParams;
|
|
@@ -118,4 +113,4 @@ declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input:
|
|
|
118
113
|
declare function makeIdFiltersToMatchWithQuery(input: string | RegExp | readonly (string | RegExp)[]): string | RegExp | (string | RegExp)[];
|
|
119
114
|
|
|
120
115
|
//#endregion
|
|
121
|
-
export { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex,
|
|
116
|
+
export { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,13 @@ const postfixRE = /[?#].*$/;
|
|
|
3
3
|
function cleanUrl(url) {
|
|
4
4
|
return url.replace(postfixRE, "");
|
|
5
5
|
}
|
|
6
|
+
function extractQueryWithoutFragment(url) {
|
|
7
|
+
const questionMarkIndex = url.indexOf("?");
|
|
8
|
+
if (questionMarkIndex === -1) return "";
|
|
9
|
+
const fragmentIndex = url.indexOf("#", questionMarkIndex);
|
|
10
|
+
if (fragmentIndex === -1) return url.substring(questionMarkIndex);
|
|
11
|
+
else return url.substring(questionMarkIndex, fragmentIndex);
|
|
12
|
+
}
|
|
6
13
|
|
|
7
14
|
//#endregion
|
|
8
15
|
//#region src/composable-filters.ts
|
|
@@ -118,13 +125,8 @@ function exclude(expr) {
|
|
|
118
125
|
* ```
|
|
119
126
|
* @param queryFilterObject The query filter object needs to be matched.
|
|
120
127
|
* @returns a `And` FilterExpression
|
|
121
|
-
*
|
|
122
|
-
* There are three kinds of conditions are supported:
|
|
123
|
-
* 1. `boolean`: if the value is `true`, the key must exist and be truthy. if the value is `false`, the key must not exist or be falsy.
|
|
124
|
-
* 2. `string`: the key must exist and be equal to the value.
|
|
125
|
-
* 3. `RegExp`: the key must exist and match the value.
|
|
126
128
|
*/
|
|
127
|
-
function
|
|
129
|
+
function queries(queryFilter) {
|
|
128
130
|
let arr = Object.entries(queryFilter).map(([key, value]) => {
|
|
129
131
|
return new Query(key, value);
|
|
130
132
|
});
|
|
@@ -172,7 +174,7 @@ function exprInterpreter(expr, code$1, id$1, moduleType$1, ctx = {}) {
|
|
|
172
174
|
case "query": {
|
|
173
175
|
if (id$1 === void 0) throw new Error("`id` is required for `Query` expression");
|
|
174
176
|
if (!ctx.urlSearchParamsCache) {
|
|
175
|
-
let
|
|
177
|
+
let queryString = extractQueryWithoutFragment(id$1);
|
|
176
178
|
ctx.urlSearchParamsCache = new URLSearchParams(queryString);
|
|
177
179
|
}
|
|
178
180
|
let urlParams = ctx.urlSearchParamsCache;
|
|
@@ -181,7 +183,7 @@ function exprInterpreter(expr, code$1, id$1, moduleType$1, ctx = {}) {
|
|
|
181
183
|
else if (typeof expr.pattern === "string") return urlParams.get(expr.key) === expr.pattern;
|
|
182
184
|
else return expr.pattern.test(urlParams.get(expr.key) ?? "");
|
|
183
185
|
}
|
|
184
|
-
default: throw new Error(`Expression
|
|
186
|
+
default: throw new Error(`Expression ${JSON.stringify(expr)} is not expected.`);
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
189
|
|
|
@@ -234,4 +236,4 @@ function makeRegexIdFilterToMatchWithQuery(input) {
|
|
|
234
236
|
}
|
|
235
237
|
|
|
236
238
|
//#endregion
|
|
237
|
-
export { and, code, exactRegex, exclude, exprInterpreter, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex,
|
|
239
|
+
export { and, code, exactRegex, exclude, exprInterpreter, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query };
|