Registry / http-networking / events-intercept

events-intercept

JSON →
library2.0.0jsnpmunverified

`events-intercept` is a Node.js library designed to introduce middleware-like interception capabilities to the standard `EventEmitter`. It allows developers to define functions that execute before an event's registered handlers, providing opportunities to modify event arguments, prevent event propagation, or trigger additional events based on intercepted data. The library extends `events.EventEmitter`, adding methods such as `intercept`, `interceptors`, `removeInterceptor`, and `removeAllInterceptors` to manage these pre-handler hooks. The current and last stable version is 2.0.0, released in 2015. This package is no longer actively maintained, making it unsuitable for new projects requiring ongoing support or modern JavaScript features like ES Modules. Its primary differentiator, historically, was providing a structured, waterfall-like approach to event processing, akin to request middleware, directly within the `EventEmitter` paradigm.

npm install events-intercept
INSTALL
IMPORT
SIG · EVENTS-INTERCEPT
E
events-intercept
http-networkingjavascriptv2.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

EventEmitter
✓ const EventEmitter = require('events-intercept').EventEmitter;
✗ import { EventEmitter } from 'events-intercept';
This package is CommonJS-only and does not support ES Module `import` syntax. Attempting to use `import` will result in a syntax error or a runtime error.
eventsIntercept
✓ const eventsIntercept = require('events-intercept');
✗ import eventsIntercept from 'events-intercept';
The entire module can be required, exposing the `EventEmitter` constructor as a property of the resulting object. This is a CommonJS module only.

This quickstart demonstrates how to set up `EventEmitter` with multiple interceptors for an event, showing how data can be transformed in a pipeline. It also illustrates how an interceptor can prevent the original event's handlers from being called while emitting new events.

const EventEmitter = require('events-intercept').EventEmitter; const emitter = new EventEmitter(); emitter .on('data', function(arg) { console.log(`Handler received: ${arg}`); }) .intercept('data', function(arg, done) { // Interceptor 1: Modify data console.log(`Interceptor 1 received: ${arg}`); return done(null, 'intercepted_1_' + arg); }) .intercept('data', function(arg, done) { // Interceptor 2: Further modify data console.log(`Interceptor 2 received: ${arg}`); return done(null, 'intercepted_2_' + arg); }); console.log('Emitting event with initial data...'); emitter.emit('data', 'initial data'); // Expected output: // Emitting event with initial data... // Interceptor 1 received: initial data // Interceptor 2 received: intercepted_1_initial data // Handler received: intercepted_2_initial data console.log('\nEmitting another event, but intercepting to prevent original handler...'); emitter.intercept('no-callback-event', function(arg, done) { console.log(`Interceptor for 'no-callback-event' received: ${arg}. Not calling done().`); // Do not call done(), so the original 'no-callback-event' handler is never invoked. this.emit('alternative-event', 'transformed ' + arg); }); emitter.on('no-callback-event', () => console.log('This should not log!')); emitter.on('alternative-event', (arg) => console.log(`Alternative event handler received: ${arg}`)); emitter.emit('no-callback-event', 'original data');
Debug
Known issues
breakingThe `events-intercept` package has been abandoned since 2015 and is no longer maintained. It does not receive security updates, bug fixes, or new features. Using it in new projects is strongly discouraged, and existing projects should consider migration.
fix
Consider alternatives like custom event systems, state management libraries, or modern middleware patterns for stream/message processing that are actively maintained and support modern JavaScript features.
affects: >=2.0.0
breakingThis package is CommonJS-only and lacks native ES Module (ESM) support. It cannot be directly `import`ed in ESM contexts without relying on Node.js's CJS interoperability layers, which can lead to issues or suboptimal performance in modern build environments.
fix
For CommonJS-only environments, use `require()`. For ES Module projects, evaluate if the functionality is critical enough to warrant using a legacy CJS module, or seek out an ESM-compatible alternative.
affects: >=2.0.0
gotchaRe-emitting the *same* event within its own interceptor can lead to an infinite loop, causing stack overflow errors or exhausting system resources.
fix
Avoid `this.emit(event)` for the currently intercepted `event` within an interceptor. If you need to trigger subsequent events, emit a *different* event or ensure there's a conditional break in the interception chain.
affects: >=2.0.0
gotchaBy default, a warning is emitted if more than 10 interceptors are added to a single event type, indicating a potential memory leak. While `setMaxInterceptors(n)` can change this limit (0 for no limit), a large number of interceptors can still impact performance and maintainability.
fix
Monitor for 'MaxInterceptorsExceededWarning'. If legitimate, increase the limit using `emitter.setMaxInterceptors(n)`. Otherwise, refactor your event handling to reduce the number of interceptors or consolidate related logic into fewer, more comprehensive interceptors.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Maximum number of interceptors exceeded
More than 10 interceptors (default limit) were added to a single event type, which the library flags as a potential memory leak.
fix
If this is intentional, increase the limit: `emitter.setMaxInterceptors(N)` where `N` is your desired limit (0 for no limit). If unintentional, review your code to identify and remove redundant interceptors.
RangeError: Maximum call stack size exceeded
An interceptor for an event is re-emitting the *same* event, leading to an uncontrolled recursive loop of interception and emission.
fix
Inspect interceptors for the affected event. Ensure that `this.emit('eventName', ...)` inside an interceptor does not re-emit the `eventName` that triggered the interceptor itself. Emit a *different* event, or implement logic to prevent re-emission.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
events-intercept — npm install events-intercept · libregistry