Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

emitter20

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emitter20 - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

index.d.ts

12

index.js
module.exports = function() {
var subscribers = []
return {
on: function (name, f) {
on: function (eventName, cb) {
subscribers.push({
name: name,
f: f
eventName: eventName,
cb: cb
})
},
trigger: function (name, data) {
trigger: function (eventName, data) {
subscribers
.filter(function (subscriber) {
return subscriber.name === name
return subscriber.eventName === eventName
})
.forEach(function (subscriber) {
subscriber.f(data)
subscriber.cb(data)
})

@@ -18,0 +18,0 @@ }

{
"name": "emitter20",
"version": "1.0.0",
"version": "1.0.1",
"description": "An event emitter in 20 lines of code.",

@@ -5,0 +5,0 @@ "license": "ISC",

@@ -19,5 +19,7 @@ # emitter20

var emitter = new Emitter()
emitter.on('karate-chop', function() {
console.log('Haiaaaaaa!')
})
emitter.trigger('karate-chop') // Haiaaaaa!'

@@ -30,10 +32,27 @@ ```

var emitter = new Emitter()
emitter.on('welcome', function(name) {
console.log(`Welcome {name}!`)
})
emitter.trigger('welcome', 'bob') // Welcome bob!
```
Can be used as a mixin:
```js
var assign = require('lodash.assign')
var obj = { a: 1, b: 2 }
assign(obj, new Emitter())
obj.on('karate-chop', function() {
console.log('Haiaaaaaa!')
})
obj.trigger('karate-chop') // Haiaaaaa!'
```
## License
ISC © [Raine Lourie](https://github.com/metaraine)
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc