Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@poker-apprentice/typed-event-emitter
Advanced tools
Strictly typed Node.js event emitter for TypeScript
@poker-apprentice/typed-event-emitter
Strictly typed Node.js event emitter for TypeScript.
The built-in EventEmitter
class in Node.js is useful for notifying other parts of an application that an event has taken place. However, events can be emitted using any name whether or not that event is intended to be active listeners. This means that a simple typo in an event name (e.g.: "import" instead of "imported") could result in an event being emitted that a listener is mistakenly not configured to receive.
By providing strict type validation corresponding to the function signature that is intended for listener associated with that event type, we can help ensure that our events being emitted are being received by their intended targets.
yarn add @poker-apprentice/typed-event-emitter
Given an emitter defined as follows:
import { TypedEventEmitter } from '@poker-apprentice/typed-event-emitter';
interface MyEvents {
message: (event: { username: string; body: string }) => void;
ping: () => void;
add: (a: number, b: number) => void
}
const emitter = new TypedEventEmitter<MyEvents>;
Listeners could be registered, and events could be emitted, via the following:
// VALID listeners:
emitter.on('message', ({ username, body }) => {
// `username` and `body` are both inferred as type `string`
console.log(`${username}: ${body}`);
});
emitter.on('ping', () => {
console.log('pong');
});
emitter.on('add', (a, b) => {
// `a` and `b` are both inferred as type `number`
console.log(a + b);
});
// VALID emitted events:
emitter.emit('message', { username: 'Joe', body: 'Hi there!' });
emitter.emit('ping');
emitter.emit('add', 5, 10);
However, trying to register listeners or emit events with types that do not match the structure previously defined in the MyEvents
type included above for demonstration purposed would result in type errors:
// INVALID listeners:
emitter.on('message', ({ from, subject, body }) => {});
emitter.on('ping', (timestamp) => {});
emitter.on('add', (numbers) => {});
// INVALID emitted events:
emitter.emit('message', 'Hi there!');
emitter.emit('ping', 20);
emitter.emit('add', '5', '10');
emitter.emit('not-a-legitimate-key-in-MyEvents');
FAQs
Strictly typed Node.js event emitter for TypeScript
The npm package @poker-apprentice/typed-event-emitter receives a total of 0 weekly downloads. As such, @poker-apprentice/typed-event-emitter popularity was classified as not popular.
We found that @poker-apprentice/typed-event-emitter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.