@initx-plugin/core 0.0.9 → 0.0.11

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 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
- const handlers = [];
4
- if (!Array.isArray(this.matchers) && this.matchers.matching && this.matchers.description && this.isPassed(this.matchers.matching, options.key)) {
5
- handlers.push({
6
- handler: () => this.handle(options, ...others),
7
- description: this.matchers.description
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
- const keys = Object.keys(this.matchers);
13
- for (let i = 0; i < keys.length; i++) {
14
- const matcher = this.matchers[keys[i]];
15
- const isPassed = this.isPassed(matcher.matching, options.key);
16
- if (isPassed) {
17
- handlers.push({
18
- handler: () => this.handle(options, keys[i], ...others),
19
- description: matcher.description
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
- for (let i = 0; i < this.matchers.length; i++) {
27
- const matcher = this.matchers[i];
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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@initx-plugin/core",
3
3
  "type": "module",
4
- "version": "0.0.9",
4
+ "version": "0.0.11",
5
5
  "description": "core module for initx plugins",
6
6
  "author": "imba97",
7
7
  "license": "MIT",