Gathering detailed insights and metrics for @mdingena/tiny-typed-emitter
Gathering detailed insights and metrics for @mdingena/tiny-typed-emitter
npm install @mdingena/tiny-typed-emitter
Typescript
Module System
Node Version
NPM Version
69.2
Supply Chain
93.5
Quality
76.9
Maintenance
100
Vulnerability
100
License
TypeScript (94.22%)
JavaScript (5.78%)
Total Downloads
1,749
Last Day
4
Last Week
7
Last Month
54
Last Year
1,749
31 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
3.0.1
Package Id
@mdingena/tiny-typed-emitter@3.0.1
Unpacked Size
9.59 kB
Size
3.07 kB
File Count
7
NPM Version
9.8.0
Node Version
20.5.1
Publised On
21 Mar 2024
Cumulative downloads
Total Downloads
Last day
33.3%
4
Compared to previous day
Last week
-56.3%
7
Compared to previous week
Last month
20%
54
Compared to previous month
Last year
0%
1,749
Compared to previous year
Have your events and their listeners type-checked with no overhead.
Simply add the dependency using npm:
1$ npm i tiny-typed-emitter
or using yarn:
1$ yarn add tiny-typed-emitter
1import { TypedEmitter } from 'tiny-typed-emitter';
1interface MyClassEvents { 2 'added': (el: string, wasNew: boolean) => void; 3 'deleted': (deletedCount: number) => void; 4}
EventEmitter
:
1class MyClass extends TypedEmitter<MyClassEvents> { 2 constructor() { 3 super(); 4 } 5}
1const emitter = new TypedEmitter<MyClassEvent>();
To use with generic events interface:
1interface MyClassEvents<T> { 2 'added': (el: T, wasNew: boolean) => void; 3} 4 5class MyClass<T> extends TypedEmitter<MyClassEvents<T>> { 6 7}
The type of eventNames()
is a superset of the actual event names to make
subclasses of a TypedEmitter
that introduce different events type
compatible. For example the following is possible:
1class Animal<E extends ListenerSignature<E>=ListenerSignature<unknown>> extends TypedEmitter<{spawn: () => void} & E> { 2 constructor() { 3 super(); 4 } 5} 6 7class Frog<E extends ListenerSignature<E>> extends Animal<{jump: () => void} & E> { 8} 9 10class Bird<E extends ListenerSignature<E>> extends Animal<{fly: () => void} & E> { 11} 12 13const animals: Animal[] = [new Frog(), new Bird()];
Library adds no overhead. All it does is it simply reexports renamed EventEmitter
with customized typings.
You can check lib/index.js to see the exported code.
No vulnerabilities found.
No security vulnerabilities found.