@oxog/emitter 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 +10 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -17
- package/dist/index.d.ts +41 -17
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/llms.txt +19 -7
- package/package.json +9 -6
package/llms.txt
CHANGED
|
@@ -27,7 +27,7 @@ emitter.emit('message', 'Hello!');
|
|
|
27
27
|
emitter.emit('user:login', { userId: '123' });
|
|
28
28
|
|
|
29
29
|
// Unsubscribe
|
|
30
|
-
const unsub = emitter.on('message',
|
|
30
|
+
const unsub = emitter.on('message', (msg) => console.log(msg));
|
|
31
31
|
unsub();
|
|
32
32
|
```
|
|
33
33
|
|
|
@@ -44,25 +44,30 @@ unsub();
|
|
|
44
44
|
- `once(event, handler)` - Subscribe once
|
|
45
45
|
- `prependListener(event, handler)` - Add to front
|
|
46
46
|
- `prependOnceListener(event, handler)` - Add once to front
|
|
47
|
+
- `addListener(event, handler)` - Alias for on()
|
|
47
48
|
|
|
48
49
|
### Unsubscribe
|
|
49
50
|
- `off(event, handler)` - Remove handler
|
|
50
51
|
- `offAll(event?)` - Remove all for event
|
|
51
52
|
- `clear()` - Remove all handlers
|
|
53
|
+
- `removeListener(event, handler)` - Alias for off()
|
|
54
|
+
- `removeAllListeners(event?)` - Alias for offAll()
|
|
52
55
|
|
|
53
56
|
### Emit
|
|
54
|
-
- `emit(event, payload)` - Sync emit
|
|
55
|
-
- `emitAsync(event, payload)` -
|
|
57
|
+
- `emit(event, payload)` - Sync emit, returns void
|
|
58
|
+
- `emitAsync(event, payload)` - Sequential async emit, returns Promise<unknown[]>
|
|
59
|
+
- `emitParallel(event, payload)` - Concurrent async emit, returns Promise<unknown[]> in registration order
|
|
60
|
+
(both async emits return one result per handler; `undefined` for a handler that failed)
|
|
56
61
|
|
|
57
62
|
### Inspect
|
|
58
|
-
- `listenerCount(event)` - Count listeners
|
|
63
|
+
- `listenerCount(event)` - Count listeners (also '*' and 'prefix:*')
|
|
59
64
|
- `listeners(event)` - Get handlers array
|
|
60
65
|
- `eventNames()` - Get all event names
|
|
61
66
|
- `hasListeners(event)` - Check if has listeners
|
|
62
67
|
|
|
63
68
|
### Config
|
|
64
69
|
- `getMaxListeners()` - Get limit
|
|
65
|
-
- `setMaxListeners(n)` - Set limit (0=disabled)
|
|
70
|
+
- `setMaxListeners(n)` - Set limit (0=disabled); the warning is logged once per event
|
|
66
71
|
- `isDebug()` - Check debug mode
|
|
67
72
|
- `setDebug(bool)` - Toggle debug
|
|
68
73
|
|
|
@@ -70,23 +75,30 @@ unsub();
|
|
|
70
75
|
```typescript
|
|
71
76
|
emitter.on('*', (event, payload) => {}); // All events
|
|
72
77
|
emitter.on('user:*', (event, payload) => {}); // Pattern match
|
|
78
|
+
// event: string, payload: unknown - also on emitters without an event map
|
|
73
79
|
```
|
|
80
|
+
Handlers run in registration order; prependListener()/prependOnceListener() handlers run first.
|
|
74
81
|
|
|
75
82
|
## Options
|
|
76
83
|
```typescript
|
|
77
84
|
{
|
|
78
85
|
errorHandling: 'emit' | 'throw' | 'silent',
|
|
79
|
-
onError: (error, eventName) => void,
|
|
86
|
+
onError: (error, eventName) => void, // replaces the strategy when set
|
|
80
87
|
maxListeners: number, // default: 10, 0=disabled
|
|
81
88
|
debug: boolean,
|
|
82
89
|
logger: { log, warn, error }
|
|
83
90
|
}
|
|
84
91
|
```
|
|
85
92
|
|
|
93
|
+
Error handling: 'emit' passes handler errors to 'error' listeners (logged if none);
|
|
94
|
+
'throw' re-throws from emit()/emitAsync()/emitParallel(). emit() cannot throw a rejection
|
|
95
|
+
from an async handler, so with 'throw' that error is handled as with 'emit'.
|
|
96
|
+
|
|
86
97
|
## Types
|
|
87
98
|
```typescript
|
|
88
|
-
type EventMap = Record<string, unknown>;
|
|
99
|
+
type EventMap = Record<string, unknown>; // createEmitter<T extends object>: plain interfaces work too
|
|
89
100
|
type Handler<T> = (payload: T) => MaybePromise<unknown>;
|
|
90
101
|
type WildcardHandler = (event: string, payload: unknown) => MaybePromise<unknown>;
|
|
102
|
+
type PatternHandler = (event: string, payload: unknown) => MaybePromise<unknown>;
|
|
91
103
|
type Unsubscribe = () => void;
|
|
92
104
|
```
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxog/emitter",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Type-safe event emitter with wildcard support, async emit, and configurable error handling",
|
|
5
5
|
"author": "Ersin Koç",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/ersinkoc/
|
|
9
|
+
"url": "git+https://github.com/ersinkoc/Emitter.git"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://emitter.oxog.dev",
|
|
12
12
|
"keywords": [
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"types": "./dist/index.d.cts",
|
|
37
37
|
"default": "./dist/index.cjs"
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
40
41
|
},
|
|
41
42
|
"files": [
|
|
42
43
|
"dist",
|
|
@@ -52,12 +53,14 @@
|
|
|
52
53
|
"test": "vitest run",
|
|
53
54
|
"test:watch": "vitest",
|
|
54
55
|
"test:coverage": "vitest run --coverage",
|
|
55
|
-
"lint": "eslint src tests",
|
|
56
|
+
"lint": "eslint src tests --max-warnings=0",
|
|
56
57
|
"lint:fix": "eslint src tests --fix",
|
|
57
58
|
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
58
59
|
"format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
59
|
-
"typecheck": "tsc --noEmit",
|
|
60
|
-
"prepublishOnly": "npm run build && npm run test:
|
|
60
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
61
|
+
"prepublishOnly": "npm run check && npm run build && npm run test:package",
|
|
62
|
+
"test:package": "node scripts/check-package.mjs",
|
|
63
|
+
"check": "npm run lint && npm run typecheck && npm run test:coverage"
|
|
61
64
|
},
|
|
62
65
|
"dependencies": {},
|
|
63
66
|
"devDependencies": {
|