Gathering detailed insights and metrics for strict-event-emitter
Gathering detailed insights and metrics for strict-event-emitter
Gathering detailed insights and metrics for strict-event-emitter
Gathering detailed insights and metrics for strict-event-emitter
strict-event-emitter-types
Strictly and safely type any EventEmitter-like interface on any object
eventemitter-strict
A eventemitter with typescript full support
strict-event-emitter-once
Promise based `once` for strict-event-emitter
strict-event-emitter-fork
Type-safe implementation of EventEmitter for browser and Node.js
npm install strict-event-emitter
Typescript
Module System
Node Version
NPM Version
99.6
Supply Chain
92.3
Quality
75.9
Maintenance
100
Vulnerability
100
License
TypeScript (99.11%)
JavaScript (0.89%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
65 Stars
66 Commits
7 Forks
2 Watchers
2 Branches
7 Contributors
Updated on Mar 20, 2025
Minified
Minified + Gzipped
Latest Version
0.5.1
Package Id
strict-event-emitter@0.5.1
Unpacked Size
44.67 kB
Size
7.02 kB
File Count
7
NPM Version
9.6.7
Node Version
18.17.1
Published on
Sep 21, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A type-safe implementation of EventEmitter
for browser and Node.js.
Despite event emitters potentially accepting any runtime value, defining a strict event contract is crucial when developing complex event-driven architectures. Unfortunately, the native type definitions for Node's EventEmitter
annotate event names as string
, which forbids any stricter type validation.
1// index.js 2const emitter = new EventEmitter() 3 4// Let's say our application expects a "ping" 5// event with the number payload. 6emitter.on('ping', (n: number) => {}) 7 8// We can, however, emit a different event by mistake. 9emitter.emit('pong', 1) 10 11// Or even the correct event with the wrong data. 12emitter.emit('ping', 'wait, not a number')
The purpose of this library is to provide an EventEmitter
instance that can accept a generic describing the expected events contract.
1import { Emitter } from 'strict-event-emitter' 2 3// Define a strict events contract where keys 4// represent event names and values represent 5// the list of arguments expected in ".emit()". 6type Events = { 7 ping: [number] 8} 9 10const emitter = new Emitter<Events>() 11emitter.addListener('ping', (n) => { 12 // "n" argument type is inferred as "number'. 13}) 14 15emitter.emit('ping', 10) // OK 16emitter.emit('unknown', 10) // TypeError (invalid event name) 17emitter.emit('ping', 'wait, not a number') // TypeError (invalid data)
This library is also a custom EventEmitter
implementation, which makes it compatible with other environments, like browsers or React Native.
1npm install strict-event-emitter
1import { Emitter } from 'strict-event-emitter' 2 3// 1. Define an interface that describes your events. 4// Set event names as the keys, and their expected payloads as values. 5interface Events { 6 connect: [id: string] 7 disconnect: [id: string] 8} 9 10// 2. Create a strict emitter and pass the previously defined "Events" 11// as its first generic argument. 12const emitter = new Emitter<Events>() 13 14// 3. Use the "emitter" the same way you'd use the regular "EventEmitter" instance. 15emitter.addListener('connect', (id) => {}) 16emitter.emit('connect', 'abc-123')
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
Found 5/30 approved changesets -- score normalized to 1
Reason
9 existing vulnerabilities detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-26
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