Gathering detailed insights and metrics for @akolos/event-emitter
Gathering detailed insights and metrics for @akolos/event-emitter
A collection of small node packages (written in TypeScript) that I feel aren't significant enough to have their own repo, lest I have dozens of tiny repos on my github account.
npm install @akolos/event-emitter
Typescript
Module System
Node Version
NPM Version
66.2
Supply Chain
87.8
Quality
75.8
Maintenance
100
Vulnerability
100
License
TypeScript (94.54%)
Python (3.15%)
JavaScript (2.31%)
Total Downloads
11,262
Last Day
9
Last Week
31
Last Month
170
Last Year
1,913
56 Commits
2 Watching
11 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
3.0.3
Package Id
@akolos/event-emitter@3.0.3
Unpacked Size
50.20 kB
Size
11.72 kB
File Count
57
NPM Version
8.8.0
Node Version
18.1.0
Cumulative downloads
Total Downloads
Last day
-10%
9
Compared to previous day
Last week
-32.6%
31
Compared to previous week
Last month
157.6%
170
Compared to previous month
Last year
-45.5%
1,913
Compared to previous year
A strongly-typed Node-style event emitter written in TypeScript.
1import { EventEmitter } from '@akolos/event-emitter'; 2 3export interface MyEvents { 4 eventOne: (fooCount: number) => void; 5 eventTwo: (fooCount: number, fooText: string) => void; 6} 7 8const emitter = new EventEmitter<MyEvents>(); 9emitter.on('eventOne', (fooCount: number) => console.log(fooCount)); 10emitter.emit('eventOne', 1); 11 12emitter.on('eventTwo', (fooCount: number, fooText: string) => console.log(fooCount, fooText)); 13emitter.emit('eventTwo', 2, 'second event'); 14 15emitter.emit('eventTwo', 'text', 2); // Causes typechecking error.
This version is convenient for quickly adding event emitter functionality to an existing class.
It publicly exposes the on
/off
methods but protects the emit
method.
1class MyClass extends InheritableEventEmitter<MyEvents> {} 2 3const myClass = new MyClass(); 4myClass.on('eventOne', (fooCount: number) => console.log(fooCount));
The EventSource<T>
interface represents anything that can emit events that can be listened to. EventEmitter
and InheritableEventEmitter
both implement it.
Handler<Events, EventName>
gives the type of the handler used to handle a specific event.
1type EventOneHandler = Handler<MyEvents, 'eventOne'>; // (fooCount: number) => void;
HandlerParams<Events, EventName>
is similar to Handler
, but it just gives the parameters as a named tuple.
1type EventOneHandler = HandlerParams<MyEvents, 'eventOne'>; // [fooCount: number]
1class MyClass extends SomeOtherClass { 2 private readonly eventEmitter = new EventEmitter<MyEvents>(); 3 4 public readonly on = eventEmitter.makeDelegate('on', this); 5 public readonly off = eventEmitter.makeDelegate('off', this); 6 protected readonly emit = eventEmitter.makeDelegate('emit', this);i 7}
Copyright 2022 Andrew Kolos
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
No security vulnerabilities found.