@initx-plugin/core 0.0.7 → 0.0.9

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
@@ -1,8 +1,20 @@
1
1
  type MaybeArray<T> = T | T[];
2
2
  type MaybePromise<T> = T | Promise<T>;
3
- type BaseMatchers = MaybeArray<string | RegExp>;
3
+ interface BaseMatchers {
4
+ matching: MaybeArray<string | RegExp>;
5
+ /**
6
+ * Description of the handler
7
+ *
8
+ * If multiple handlers are matched, this description will be displayed
9
+ */
10
+ description: string;
11
+ }
4
12
  type TypeMatchers = Record<string, BaseMatchers>;
5
- type Matchers = BaseMatchers | TypeMatchers;
13
+ type Matchers = MaybeArray<BaseMatchers> | TypeMatchers;
14
+ interface HandlerInfo {
15
+ handler: () => MaybePromise<void>;
16
+ description: string;
17
+ }
6
18
  interface InitxOptions {
7
19
  /**
8
20
  * Matching string
@@ -27,9 +39,9 @@ interface InitxOptions {
27
39
  declare abstract class InitxHandler {
28
40
  abstract matchers: Matchers;
29
41
  abstract handle(options: InitxOptions, ...others: string[]): MaybePromise<void>;
30
- run(options: InitxOptions, ...others: string[]): Promise<void>;
42
+ run(options: InitxOptions, ...others: string[]): HandlerInfo[];
31
43
  private isObject;
32
44
  private isPassed;
33
45
  }
34
46
 
35
- export { InitxHandler, type InitxOptions };
47
+ export { type HandlerInfo, InitxHandler, type InitxOptions };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,20 @@
1
1
  type MaybeArray<T> = T | T[];
2
2
  type MaybePromise<T> = T | Promise<T>;
3
- type BaseMatchers = MaybeArray<string | RegExp>;
3
+ interface BaseMatchers {
4
+ matching: MaybeArray<string | RegExp>;
5
+ /**
6
+ * Description of the handler
7
+ *
8
+ * If multiple handlers are matched, this description will be displayed
9
+ */
10
+ description: string;
11
+ }
4
12
  type TypeMatchers = Record<string, BaseMatchers>;
5
- type Matchers = BaseMatchers | TypeMatchers;
13
+ type Matchers = MaybeArray<BaseMatchers> | TypeMatchers;
14
+ interface HandlerInfo {
15
+ handler: () => MaybePromise<void>;
16
+ description: string;
17
+ }
6
18
  interface InitxOptions {
7
19
  /**
8
20
  * Matching string
@@ -27,9 +39,9 @@ interface InitxOptions {
27
39
  declare abstract class InitxHandler {
28
40
  abstract matchers: Matchers;
29
41
  abstract handle(options: InitxOptions, ...others: string[]): MaybePromise<void>;
30
- run(options: InitxOptions, ...others: string[]): Promise<void>;
42
+ run(options: InitxOptions, ...others: string[]): HandlerInfo[];
31
43
  private isObject;
32
44
  private isPassed;
33
45
  }
34
46
 
35
- export { InitxHandler, type InitxOptions };
47
+ export { type HandlerInfo, InitxHandler, type InitxOptions };
package/dist/index.mjs CHANGED
@@ -1,22 +1,39 @@
1
1
  class InitxHandler {
2
- async run(options, ...others) {
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;
10
+ }
3
11
  if (this.isObject(this.matchers)) {
4
12
  const keys = Object.keys(this.matchers);
5
13
  for (let i = 0; i < keys.length; i++) {
6
14
  const matcher = this.matchers[keys[i]];
7
- const isPassed2 = this.isPassed(matcher, options.key);
8
- if (isPassed2) {
9
- this.handle(options, keys[i], ...others);
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
+ });
10
21
  break;
11
22
  }
12
23
  }
13
- return;
24
+ return handlers;
14
25
  }
15
- const isPassed = this.isPassed(this.matchers, options.key);
16
- if (!isPassed) {
17
- return;
26
+ for (let i = 0; i < this.matchers.length; i++) {
27
+ const matcher = this.matchers[i];
28
+ const isPassed = this.isPassed(matcher.matching, options.key);
29
+ if (isPassed) {
30
+ handlers.push({
31
+ handler: () => this.handle(options, ...others),
32
+ description: matcher.description
33
+ });
34
+ }
18
35
  }
19
- await this.handle(options, ...others);
36
+ return handlers;
20
37
  }
21
38
  isObject(value) {
22
39
  return typeof value === "object" && value !== null && !Array.isArray(value);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@initx-plugin/core",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "description": "core module for initx plugins",
6
6
  "author": "imba97",
7
7
  "license": "MIT",