hookified 1.1.0 → 1.2.1
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 +5 -5
- package/dist/index.cjs +0 -19
- package/dist/index.js +0 -19
- package/package.json +5 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Event Emitting and Async Middleware Hooks
|
|
4
4
|
|
|
5
5
|
[](https://github.com/jaredwray/hookified/actions/workflows/tests.yaml)
|
|
6
6
|
[](https://github.com/jaredwray/hookified/blob/master/LICENSE)
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
## Features
|
|
12
12
|
- Simple replacement for EventEmitter
|
|
13
13
|
- Async Middleware Hooks for Your Methods
|
|
14
|
-
- ESM / CJS and Nodejs 20+
|
|
14
|
+
- ESM / CJS with Types and Nodejs 20+
|
|
15
15
|
- Maintained on a regular basis!
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
@@ -20,7 +20,7 @@ npm install hookified --save
|
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
|
-
This was built because we constantly wanted hooks and events extended on libraires we are building such as [Keyv](https://keyv.org) and [Cacheable](https://cacheable.org). This is a simple way to add hooks and events
|
|
23
|
+
This was built because we constantly wanted hooks and events extended on libraires we are building such as [Keyv](https://keyv.org) and [Cacheable](https://cacheable.org). This is a simple way to add hooks and events to your classes.
|
|
24
24
|
|
|
25
25
|
```javascript
|
|
26
26
|
import { Hookified } from 'hookified';
|
|
@@ -31,7 +31,7 @@ class MyClass extends Hookified {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async myMethodEmittingEvent() {
|
|
34
|
-
|
|
34
|
+
this.emit('message', 'Hello World'); //using Emittery
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
//with hooks you can pass data in and if they are subscribed via onHook they can modify the data
|
package/dist/index.cjs
CHANGED
|
@@ -73,14 +73,6 @@ var Eventified = class {
|
|
|
73
73
|
for (const listener of listeners) {
|
|
74
74
|
listener(...arguments_);
|
|
75
75
|
}
|
|
76
|
-
} else if (event === "error") {
|
|
77
|
-
if (arguments_[0] instanceof Error) {
|
|
78
|
-
throw arguments_[0];
|
|
79
|
-
} else {
|
|
80
|
-
const error = new CustomEventError(arguments_[0]);
|
|
81
|
-
error.context = arguments_[0];
|
|
82
|
-
throw error;
|
|
83
|
-
}
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
78
|
// Get all listeners for a specific event
|
|
@@ -105,17 +97,6 @@ var Eventified = class {
|
|
|
105
97
|
}
|
|
106
98
|
}
|
|
107
99
|
};
|
|
108
|
-
var CustomEventError = class _CustomEventError extends Error {
|
|
109
|
-
context;
|
|
110
|
-
constructor(message, context) {
|
|
111
|
-
super(message);
|
|
112
|
-
this.context = context;
|
|
113
|
-
if (Error.captureStackTrace) {
|
|
114
|
-
Error.captureStackTrace(this, _CustomEventError);
|
|
115
|
-
}
|
|
116
|
-
this.name = this.constructor.name;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
100
|
|
|
120
101
|
// src/index.ts
|
|
121
102
|
var Hookified = class extends Eventified {
|
package/dist/index.js
CHANGED
|
@@ -46,14 +46,6 @@ var Eventified = class {
|
|
|
46
46
|
for (const listener of listeners) {
|
|
47
47
|
listener(...arguments_);
|
|
48
48
|
}
|
|
49
|
-
} else if (event === "error") {
|
|
50
|
-
if (arguments_[0] instanceof Error) {
|
|
51
|
-
throw arguments_[0];
|
|
52
|
-
} else {
|
|
53
|
-
const error = new CustomEventError(arguments_[0]);
|
|
54
|
-
error.context = arguments_[0];
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
49
|
}
|
|
58
50
|
}
|
|
59
51
|
// Get all listeners for a specific event
|
|
@@ -78,17 +70,6 @@ var Eventified = class {
|
|
|
78
70
|
}
|
|
79
71
|
}
|
|
80
72
|
};
|
|
81
|
-
var CustomEventError = class _CustomEventError extends Error {
|
|
82
|
-
context;
|
|
83
|
-
constructor(message, context) {
|
|
84
|
-
super(message);
|
|
85
|
-
this.context = context;
|
|
86
|
-
if (Error.captureStackTrace) {
|
|
87
|
-
Error.captureStackTrace(this, _CustomEventError);
|
|
88
|
-
}
|
|
89
|
-
this.name = this.constructor.name;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
73
|
|
|
93
74
|
// src/index.ts
|
|
94
75
|
var Hookified = class extends Eventified {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hookified",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Event and Middleware Hooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
},
|
|
27
27
|
"keywords": [
|
|
28
28
|
"hooks",
|
|
29
|
-
"emittery",
|
|
30
29
|
"eventemitter",
|
|
31
30
|
"eventemitter3",
|
|
32
31
|
"middleware",
|
|
@@ -37,7 +36,6 @@
|
|
|
37
36
|
"event-driven",
|
|
38
37
|
"event-emitter",
|
|
39
38
|
"hook-handlers",
|
|
40
|
-
"async-hooks",
|
|
41
39
|
"middleware",
|
|
42
40
|
"emit",
|
|
43
41
|
"event-management",
|
|
@@ -58,12 +56,12 @@
|
|
|
58
56
|
},
|
|
59
57
|
"homepage": "https://github.com/jaredwray/hookified#readme",
|
|
60
58
|
"devDependencies": {
|
|
61
|
-
"@vitest/coverage-v8": "^2.1.
|
|
62
|
-
"docula": "^0.9.
|
|
59
|
+
"@vitest/coverage-v8": "^2.1.2",
|
|
60
|
+
"docula": "^0.9.3",
|
|
63
61
|
"rimraf": "^6.0.1",
|
|
64
62
|
"tsup": "^8.3.0",
|
|
65
|
-
"typescript": "^5.6.
|
|
66
|
-
"vitest": "^2.1.
|
|
63
|
+
"typescript": "^5.6.3",
|
|
64
|
+
"vitest": "^2.1.2",
|
|
67
65
|
"xo": "^0.59.3"
|
|
68
66
|
},
|
|
69
67
|
"files": [
|