@initx-plugin/core 0.0.9 → 0.0.10
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.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +47 -22
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -40,6 +40,11 @@ declare abstract class InitxHandler {
|
|
|
40
40
|
abstract matchers: Matchers;
|
|
41
41
|
abstract handle(options: InitxOptions, ...others: string[]): MaybePromise<void>;
|
|
42
42
|
run(options: InitxOptions, ...others: string[]): HandlerInfo[];
|
|
43
|
+
private matchBaseMatchers;
|
|
44
|
+
private matchArrayBaseMatchers;
|
|
45
|
+
private matchTypeMatchers;
|
|
46
|
+
private isBaseMatchers;
|
|
47
|
+
private isArrayBaseMatchers;
|
|
43
48
|
private isObject;
|
|
44
49
|
private isPassed;
|
|
45
50
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,11 @@ declare abstract class InitxHandler {
|
|
|
40
40
|
abstract matchers: Matchers;
|
|
41
41
|
abstract handle(options: InitxOptions, ...others: string[]): MaybePromise<void>;
|
|
42
42
|
run(options: InitxOptions, ...others: string[]): HandlerInfo[];
|
|
43
|
+
private matchBaseMatchers;
|
|
44
|
+
private matchArrayBaseMatchers;
|
|
45
|
+
private matchTypeMatchers;
|
|
46
|
+
private isBaseMatchers;
|
|
47
|
+
private isArrayBaseMatchers;
|
|
43
48
|
private isObject;
|
|
44
49
|
private isPassed;
|
|
45
50
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
class InitxHandler {
|
|
2
2
|
run(options, ...others) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
return handlers;
|
|
3
|
+
if (this.isBaseMatchers(this.matchers)) {
|
|
4
|
+
return this.matchBaseMatchers(this.matchers, options, ...others);
|
|
5
|
+
}
|
|
6
|
+
if (this.isArrayBaseMatchers(this.matchers)) {
|
|
7
|
+
return this.matchArrayBaseMatchers(this.matchers, options, ...others);
|
|
10
8
|
}
|
|
11
9
|
if (this.isObject(this.matchers)) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return handlers;
|
|
10
|
+
return this.matchTypeMatchers(this.matchers, options, ...others);
|
|
11
|
+
}
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
// BaseMatchers
|
|
15
|
+
matchBaseMatchers(matchers, options, ...others) {
|
|
16
|
+
if (!this.isPassed(matchers.matching, options.key)) {
|
|
17
|
+
return [];
|
|
25
18
|
}
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
handler: () => this.handle(options, ...others),
|
|
22
|
+
description: matchers.description
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
matchArrayBaseMatchers(matchers, options, ...others) {
|
|
27
|
+
const handlers = [];
|
|
28
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
29
|
+
const matcher = matchers[i];
|
|
28
30
|
const isPassed = this.isPassed(matcher.matching, options.key);
|
|
29
31
|
if (isPassed) {
|
|
30
32
|
handlers.push({
|
|
@@ -35,6 +37,29 @@ class InitxHandler {
|
|
|
35
37
|
}
|
|
36
38
|
return handlers;
|
|
37
39
|
}
|
|
40
|
+
matchTypeMatchers(matchers, options, ...others) {
|
|
41
|
+
const handlers = [];
|
|
42
|
+
const keys = Object.keys(matchers);
|
|
43
|
+
for (let i = 0; i < keys.length; i++) {
|
|
44
|
+
const matcher = matchers[keys[i]];
|
|
45
|
+
const isPassed = this.isPassed(matcher.matching, options.key);
|
|
46
|
+
if (isPassed) {
|
|
47
|
+
handlers.push({
|
|
48
|
+
handler: () => this.handle(options, keys[i], ...others),
|
|
49
|
+
description: matcher.description
|
|
50
|
+
});
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return handlers;
|
|
55
|
+
}
|
|
56
|
+
isBaseMatchers(matchers) {
|
|
57
|
+
const keys = Object.keys(matchers);
|
|
58
|
+
return this.isObject(matchers) && keys.length === 2 && keys.every((key) => key === "matching" || key === "description");
|
|
59
|
+
}
|
|
60
|
+
isArrayBaseMatchers(matchers) {
|
|
61
|
+
return Array.isArray(matchers) && matchers.every(this.isBaseMatchers.bind(this));
|
|
62
|
+
}
|
|
38
63
|
isObject(value) {
|
|
39
64
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
40
65
|
}
|