Installations
npm install strict-event-emitter-fork
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.18.0
NPM Version
8.19.2
Score
70.8
Supply Chain
91.3
Quality
75
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.11%)
JavaScript (0.89%)
Developer
Download Statistics
Total Downloads
178
Last Day
1
Last Week
4
Last Month
7
Last Year
47
GitHub Statistics
63 Stars
66 Commits
7 Forks
3 Watching
2 Branches
7 Contributors
Bundle Size
2.93 kB
Minified
1.08 kB
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
178
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Strict Event Emitter
A type-safe implementation of EventEmitter
for browser and Node.js.
Motivation
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.
Getting started
Install
1npm install strict-event-emitter
Use
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')
License
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
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
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/open-draft/strict-event-emitter/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/open-draft/strict-event-emitter/main.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/open-draft/strict-event-emitter/main.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
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
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Score
2.9
/10
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