Installations
npm install tiny-typed-emitter
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
14.16.0
NPM Version
7.11.1
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
binier
Download Statistics
Total Downloads
21,488,049
Last Day
30,675
Last Week
155,356
Last Month
1,057,317
Last Year
11,886,239
GitHub Statistics
117 Stars
26 Commits
11 Forks
4 Watching
1 Branches
3 Contributors
Bundle Size
281.00 B
Minified
218.00 B
Minified + Gzipped
Package Meta Information
Latest Version
2.1.0
Package Id
tiny-typed-emitter@2.1.0
Size
2.32 kB
NPM Version
7.11.1
Node Version
14.16.0
Publised On
24 Jul 2021
Total Downloads
Cumulative downloads
Total Downloads
21,488,049
Last day
11.5%
30,675
Compared to previous day
Last week
-32.7%
155,356
Compared to previous week
Last month
-11.3%
1,057,317
Compared to previous month
Last year
150.2%
11,886,239
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
2
tiny-typed-emitter
Have your events and their listeners type-checked with no overhead.
Install
Simply add the dependency using npm:
1$ npm i tiny-typed-emitter
or using yarn:
1$ yarn add tiny-typed-emitter
Usage
- import tiny-typed-emitter library:
1import { TypedEmitter } from 'tiny-typed-emitter';
- define events and their listener signatures (note: quotes around event names are not mandatory):
1interface MyClassEvents { 2 'added': (el: string, wasNew: boolean) => void; 3 'deleted': (deletedCount: number) => void; 4}
- on this step depending on your use case, you can:
- define your custom class extending
EventEmitter
:1class MyClass extends TypedEmitter<MyClassEvents> { 2 constructor() { 3 super(); 4 } 5}
- create new event emitter instance:
1const emitter = new TypedEmitter<MyClassEvent>();
Generic events interface
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}
Compatible subclasses with different events
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()];
No Overhead
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.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 2/22 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More