Gathering detailed insights and metrics for strict-event-emitter-fork
Gathering detailed insights and metrics for strict-event-emitter-fork
Gathering detailed insights and metrics for strict-event-emitter-fork
Gathering detailed insights and metrics for strict-event-emitter-fork
npm install strict-event-emitter-fork
Typescript
Module System
Node Version
NPM Version
70.8
Supply Chain
91.3
Quality
75
Maintenance
100
Vulnerability
100
License
TypeScript (99.11%)
JavaScript (0.89%)
Total Downloads
178
Last Day
1
Last Week
4
Last Month
7
Last Year
47
63 Stars
66 Commits
7 Forks
3 Watching
2 Branches
7 Contributors
Minified
Minified + Gzipped
Latest Version
0.4.4
Package Id
strict-event-emitter-fork@0.4.4
Unpacked Size
14.29 kB
Size
3.85 kB
File Count
8
NPM Version
8.19.2
Node Version
16.18.0
Publised On
04 Feb 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
4
Compared to previous week
Last month
250%
7
Compared to previous month
Last year
-64.1%
47
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 binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
6 existing vulnerabilities detected
Details
Reason
Found 5/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
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