New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

eventemitter-ts

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventemitter-ts

Typed EventEmitter classes for use with TypeScript

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

eventemitter-ts

Typed EventEmitter classes for use with TypeScript.

Installation

npm install eventemitter-ts

Usage

All classes use the same interface as Node's built-in EventEmitter, but with generics for strict event types.

TypedEventEmitter

import { TypedEventEmitter } from 'eventemitter-ts';

interface Events {
    'foo': number;
    'bar': string;
}

const ee = new TypedEventEmitter<Events>();

ee.on('foo', (arg: number) => {}); // OK
ee.on('bar', (arg: string) => {}); // OK
ee.on('baz', (arg: number) => {}); // Error! 'baz' is not a valid event
ee.on('foo', (arg: string) => {}); // Error! 'foo' event does not emit argument of type string

ProtectedEventEmitter

import { ProtectedEventEmitter } from 'eventemitter-ts';

interface Events {
    'foo': number;
    'bar': string;
}

/**
 * Emits 'foo' event once every second.
 */
class MyEventEmitter extends ProtectedEventEmitter<Events> {
    constructor() {
        super();
        setInterval(() => {
            this.protectedEmit('foo', 123);
        }, 1000);
    }
}

const ee = new MyEventEmitter();
ee.on('foo', (arg: number) => {}); // OK
ee.emit('foo', 123); // NOP -- doesn't do anything, always returns false

FAQs

Package last updated on 25 Jun 2018

Did you know?

Socket

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.

Install

Related posts