
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@herbcaudill/eventemitter42
Advanced tools
Stripped-down TypeScript/ESM eventemitter with strong typing.
This is a Typescript/ESM adaptation of eventemitter3.
The motivation behind this is that I often use a pattern of awaiting for a promisified event, and neither me nor the internet could get strong typing on the result of that promise.
type TestEvents = {
foo: (payload: { bar: string }) => void
}
const testEmitter = new EventEmitter<TestEvents>()
const { bar } = await eventPromise(testEmitter, 'foo')
// error: Property 'bar' does not exist on type 'unknown'.
As a bonus this library includes that eventPromise function.
const { bar } = await eventPromise(testEmitter, 'foo')
// âś… bar is `string`
I left out some eventemitter3 features that I've never used:
eventNames, listeners and listenerCount methodsWith eventemitter3, you have various options for defining event listener signatures. In this library, event types can only be expressed as a map of function signatures:
const testEmitter = new EventEmitter<{
foo: (p: string) => void
bar: (p: number) => void
}>()
// won't work:
const no = new EventEmitter<'data'>() ❌
const nope = new EventEmitter<{foo: string; bar: number}>() ❌
$ pnpm add @herbcaudill/eventemitter42
import { EventEmitter, eventPromise } from '@herbcaudill/eventemitter42'
class MyEmitter extends EventEmitter<TestEvents> {
doSomething() {
this.emit('foo', 'here is a payload')
}
doSomethingElse() {
this.emit('bar', 42)
}
}
const emitter = new MyEmitter()
emitter.on('foo', p => {
console.log(p) // 'here is a payload'
})
emitter.doSomething()
setTimeout(() => emitter.doSomethingElse(), 1000)
const result = await eventPromise(emitter, 'bar')
console.log(result) // '42' (after a second)
FAQs
Stripped-down TypeScript/ESM eventemitter with strong typing.
The npm package @herbcaudill/eventemitter42 receives a total of 411 weekly downloads. As such, @herbcaudill/eventemitter42 popularity was classified as not popular.
We found that @herbcaudill/eventemitter42 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.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.