Socket
Socket
Sign inDemoInstall

modify-event

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

modify-event

Modify the value of the specific object's event


Version published
Maintainers
1
Weekly downloads
516
decreased by-5.49%
Bundle size
398 bytes
Minified + gzipped

Weekly downloads

Readme

Source

modify-event

npm version Build Status Coverage Status

Modify the value of the specific object's event

const {EventEmitter} = require('events');
const modifyEvent = require('modify-event');

const emitter = new EventEmitter();

modifyEvent(emitter, 'foo', val => val * 2);

emitter.on('foo', data => {
  data; //=> 2
});

emitter.emit('foo', 1);

Installation

Use npm.

npm install modify-event

API

const modifyEvent = require('modify-event');

modifyEvent(eventEmitter, eventName, modifier)

eventEmitter: EventEmitter
eventName: string symbol (event name)
modifier: Function
Return: EventEmitter (a reference to the first argument)

It changes the first argument of the event listeners for a given event, in response to the return value of the modifier function.

const {EventEmitter} = require('events');
const modifyEvent = require('modify-event');

const emitter = new EventEmitter();
const eventName = Symbol('custom event name');

modifyEvent(emitter, eventName, val => `${val}b`);
modifyEvent(emitter, eventName, val => `${val}c`);

emitter
.on(eventName, listener)
.emit(eventName, 'a');

function listener(data) {
  data; //=> 'abc'
}

License

Copyright (c) 2015 - 2019 Shinnosuke Watanabe

Licensed under the MIT License.

Keywords

FAQs

Last updated on 10 Jan 2019

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc