@arkstack/foundry 0.19.2 → 0.19.3
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/README.md +10 -10
- package/dist/index.js +9 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,12 +23,12 @@ A global, named hook registry for extending Arkstack internals without modifying
|
|
|
23
23
|
Registers a hook. Multiple calls for the same name are merged.
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
import { Hook } from '@arkstack/foundry'
|
|
26
|
+
import { Hook } from '@arkstack/foundry'
|
|
27
27
|
|
|
28
28
|
Hook.set('request:handle', {
|
|
29
29
|
before: (ctx) => console.log('before handler'),
|
|
30
30
|
after: (ctx) => console.log('after handler'),
|
|
31
|
-
})
|
|
31
|
+
})
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
#### `Hook.get(name, pos?)`
|
|
@@ -36,8 +36,8 @@ Hook.set('request:handle', {
|
|
|
36
36
|
Retrieves the full hook object or a specific positional handler.
|
|
37
37
|
|
|
38
38
|
```ts
|
|
39
|
-
const hook = Hook.get('request:handle')
|
|
40
|
-
const before = Hook.get('request:handle', 'before')
|
|
39
|
+
const hook = Hook.get('request:handle') // IHook | undefined
|
|
40
|
+
const before = Hook.get('request:handle', 'before') // function | undefined
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
#### `Hook.has(name, pos?)`
|
|
@@ -45,8 +45,8 @@ const before = Hook.get('request:handle', 'before'); // function | undefined
|
|
|
45
45
|
Checks whether a hook (or a specific position within it) exists.
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
|
-
Hook.has('request:handle')
|
|
49
|
-
Hook.has('request:handle', 'after')
|
|
48
|
+
Hook.has('request:handle') // true | false
|
|
49
|
+
Hook.has('request:handle', 'after') // true | false
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
#### `Hook.unset(name?, pos?)`
|
|
@@ -54,9 +54,9 @@ Hook.has('request:handle', 'after'); // true | false
|
|
|
54
54
|
Removes a hook or a single positional handler. If the hook becomes empty after removal, it is deleted entirely. Called with no arguments, it delegates to `Hook.clear()`.
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
|
-
Hook.unset('request:handle', 'before')
|
|
58
|
-
Hook.unset('request:handle')
|
|
59
|
-
Hook.unset()
|
|
57
|
+
Hook.unset('request:handle', 'before') // removes only the 'before' handler
|
|
58
|
+
Hook.unset('request:handle') // removes the entire hook
|
|
59
|
+
Hook.unset() // clears all hooks
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
#### `Hook.getAll()`
|
|
@@ -64,7 +64,7 @@ Hook.unset(); // clears all hooks
|
|
|
64
64
|
Returns all registered hooks as a plain record.
|
|
65
65
|
|
|
66
66
|
```ts
|
|
67
|
-
const hooks = Hook.getAll()
|
|
67
|
+
const hooks = Hook.getAll()
|
|
68
68
|
// { 'request:handle': { before: fn, after: fn } }
|
|
69
69
|
```
|
|
70
70
|
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,9 @@ var Hook = class {
|
|
|
3
3
|
static hooks = /* @__PURE__ */ new Map();
|
|
4
4
|
/**
|
|
5
5
|
* Hooks define code that should run within defined boundaries to add extra functionalities.
|
|
6
|
-
*
|
|
7
|
-
* @param name
|
|
8
|
-
* @param value
|
|
6
|
+
*
|
|
7
|
+
* @param name
|
|
8
|
+
* @param value
|
|
9
9
|
*/
|
|
10
10
|
static set(name, hook) {
|
|
11
11
|
const oldhook = this.hooks.get(name) ?? {};
|
|
@@ -16,8 +16,8 @@ var Hook = class {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Check if a hook is defined by name
|
|
19
|
-
*
|
|
20
|
-
* @param name
|
|
19
|
+
*
|
|
20
|
+
* @param name
|
|
21
21
|
*/
|
|
22
22
|
static has(name, pos) {
|
|
23
23
|
if (pos && this.hooks.has(name)) return Boolean(this.get(name, pos));
|
|
@@ -34,8 +34,8 @@ var Hook = class {
|
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Retrieve all defined hooks
|
|
37
|
-
*
|
|
38
|
-
* @param name
|
|
37
|
+
*
|
|
38
|
+
* @param name
|
|
39
39
|
*/
|
|
40
40
|
static getAll = () => {
|
|
41
41
|
const hooks = {};
|
|
@@ -44,8 +44,8 @@ var Hook = class {
|
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
46
|
* Remove the defined hook
|
|
47
|
-
*
|
|
48
|
-
* @param name
|
|
47
|
+
*
|
|
48
|
+
* @param name
|
|
49
49
|
*/
|
|
50
50
|
static unset(name, pos) {
|
|
51
51
|
if (name && this.hooks.has(name)) {
|
package/package.json
CHANGED