Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/modify-error-event
Modify the value of the specific object's error event
https://github.com/shinnn/modify-error-event
Last synced: 27 days ago
JSON representation
Modify the value of the specific object's error event
- Host: GitHub
- URL: https://github.com/shinnn/modify-error-event
- Owner: shinnn
- License: unlicense
- Created: 2015-04-26T04:08:53.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-02T09:48:00.000Z (about 8 years ago)
- Last Synced: 2024-09-18T03:57:52.720Z (about 2 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# modify-error-event
[![NPM version](https://img.shields.io/npm/v/modify-error-event.svg)](https://www.npmjs.com/package/modify-error-event)
[![Build Status](https://travis-ci.org/shinnn/modify-error-event.svg?branch=master)](https://travis-ci.org/shinnn/modify-error-event)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/modify-error-event.svg)](https://coveralls.io/r/shinnn/modify-error-event)
[![dependencies Status](https://david-dm.org/shinnn/modify-error-event/status.svg)](https://david-dm.org/shinnn/modify-error-event)
[![devDependencies Status](https://david-dm.org/shinnn/modify-error-event/dev-status.svg)](https://david-dm.org/shinnn/modify-error-event?type=dev)Modify the value of the specific object's `error` [event](https://nodejs.org/api/events.html)
```javascript
const EventEmitter = require('events').EventEmitter;
const modifyErrorEvent = require('modify-error-event');let emitter = new EventEmitter();
modifyErrorEvent(emitter, err => {
err.message = 'bar';
return err;
});emitter.on('error', err => {
err.message; //=> 'bar'
});emitter.emit('error', new Error('foo'));
```## Installation
[Use npm.](https://docs.npmjs.com/cli/install)
```
npm install modify-error-event
```## API
```javascript
const modifyErrorEvent = require('modify-error-event');
```### modifyErrorEvent(*eventEmitter*, *modifier*)
*eventEmitter*: `Object` (an instance of [`EventEmitter`](https://nodejs.org/api/events.html#events_class_events_eventemitter) or its inheritance e.g. [`Stream`](https://nodejs.org/api/stream.html#stream_stream))
*modifier*: `Function`
Return: `Object` (Same as the first argument)It changes the first argument of the `error` event listeners in response to the return value of the *modifier* function.
```javascript
const EventEmitter = require('events').EventEmitter;
const modifyErrorEvent = require('modify-error-event');let emitter = new EventEmitter();
modifyErrorEvent(emitter, err => {
err.message += 'b';
return err;
});modifyErrorEvent(emitter, val => {
err.message += 'c';
return err;
});emitter
.on('error', listener)
.emit('error', new Error('a'));function listener(err) {
err.message; //=> 'abc'
}
```## License
[The Unlicense](./LICENSE).