Socket
Socket
Sign inDemoInstall

@yandeu/events

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @yandeu/events

⚡ Simplified and TypeScripted version of EventEmitter3@4.0.7


Version published
Maintainers
1
Install size
28.7 kB
Created

Readme

Source

Events

Simplified and TypeScripted version of EventEmitter3@4.0.7
(no support for Symbols)

Installation

npm install @yandeu/events

CDN

// ES2015+
https://unpkg.com/@yandeu/events/umd/events.min.js

// ES5
https://unpkg.com/@yandeu/events/umd/events.es5.min.js

Usage

const { Events } = require('@yandeu/events')

// or
// import { Events } from '@yandeu/events'

const events = new Events()

events.on('message', msg => {
  console.log(`Message: ${msg}`)
})

events.emit('message', 'Hello there!')

// will print: Message: Hello there!
// print the current version
console.log('Events VERSION: ', Events.VERSION)

TypeScript

import { Events } from '@yandeu/events'

interface EventMap {
  signal: () => void
  error: (err: string) => void
  something: (a: number, b: { color?: string }, c: [number, number, string]) => void
}

const events = new Events<EventMap>()

events.on('something', (a, b, c) => {
  console.log(a, b.color, c)
})

events.emit('something', 1, { color: 'blue' }, [2, 2, 'k'])
import type { EventListener } from '@yandeu/events'

// typed listener
const listener: EventListener<EventMap, 'error'> = err => {
  console.log('err:', err)
}

// add listener
events.on('error', listener)

// remove listener
// (once you don't need it anymore)
events.removeListener('error', listener)

License

MIT

Keywords

FAQs

Last updated on 04 Nov 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc