$ npm install event-pubsub
Small, synchronous, extensible publish/subscribe events for Node.js plus bundled and unbundled browsers.
It works with bundlers and without a bundler. Both paths execute the same native ESM source; direct browser use needs only a standard import map, not a build or transpilation step.
Release status:
6.1.1is the current npm and GitHub release.

npm install event-pubsub
import EventPubSub from 'event-pubsub';
const events = new EventPubSub();
events.on('ready', (payload) => {
console.log(payload);
});
events.emit('ready', {fast: true});
That bare import is also the bundler entry. In a native browser application with no bundler, keep the same import and add the complete import map shown below.
The same source is available directly to CommonJS on Node.js 22.12 or newer:
const EventPubSub = require('event-pubsub');
Bars show median nanoseconds per emit, whiskers show p25–p75, and dots show all seven samples. Every rate is derived from the same execution-only measurement; setup, warmup, validation, verification, serialization, file I/O, and CI orchestration are excluded. Lower latency is better. Open the interactive charts or raw schema v2 evidence.
on, once, off, emit, and reset.__proto__, constructor, and toString.list snapshots that cannot mutate the live registry.import/require(), bundled browser applications, and unbundled browser modules, without transpilation or a duplicate build.strong-type 2.0.0, resolved through the package dependency boundary with an explicit browser entry and import map.| Member | Signature | Behavior |
|---|---|---|
on |
on(type, handler, once = false) |
Register a persistent or explicitly one-shot handler. |
once |
once(type, handler) |
Register a handler removed immediately before its first call. |
off |
off(type = '*', handler = '*') |
Remove every matching handler or a whole event type. |
emit |
emit(type, ...payload) |
Run wildcard handlers, then typed handlers, synchronously. |
reset |
reset() |
Clear the complete registry. |
list |
get list() |
Return an isolated null-prototype object snapshot of handler arrays. |
All public mutators return the current instance. Event types must be strings, and on/once validate their handler immediately. For 5.x compatibility, off returns early for a missing type before validating its optional handler. Synchronous handler throws propagate to the publisher; return values and promises are ignored, so applications must handle asynchronous rejections themselves.
* subscribers run before typed subscribers and receive the emitted type as their first argument.
events.on('*', (type, ...payload) => {
console.log(type, payload);
});
events.emit('invoice.paid', {id: 42});
The wildcard list entry is exposed at Symbol.for('event-pubsub-all').
Only the exact public string * maps to the internal wildcard Symbol. The ordinary string Symbol(event-pubsub-all) remains an exact typed event name and never aliases wildcard removal.
The 6.1.1 package imports strong-type by package name. Bundlers may use its explicit browser entry; native browsers do not read npm package metadata, so the import map selects index.js directly.
<script type="importmap">
{
"imports": {
"event-pubsub": "./node_modules/event-pubsub/index.js",
"strong-type": "./node_modules/strong-type/index.js"
}
}
</script>
<script type="module">
import EventPubSub from 'event-pubsub';
</script>
That example is non-bundled browser code: the browser fetches both files from the mapped URLs and executes them directly. The paths are relative to the HTML document, so the static server must expose the shown node_modules files. Open the application through HTTP(S), not file://.
If the application uses a strict Content Security Policy, configure it to authorize the inline import-map and module scripts—for example, with an allowed nonce or hash.
If the application intentionally installs an incompatible strong-type at its root, npm keeps event-pubsub's exact 2.0.0 dependency nested. Scope the validator mapping to the event-pubsub referrer so the browser preserves that same dependency boundary:
<script type="importmap">
{
"imports": {
"event-pubsub": "./node_modules/event-pubsub/index.js",
"strong-type": "./node_modules/strong-type/index.js"
},
"scopes": {
"./node_modules/event-pubsub/": {
"strong-type": "./node_modules/event-pubsub/node_modules/strong-type/index.js"
}
}
}
</script>
Adjust the URLs to the package layout exposed by your static server. The release gate installs the packed tarball twice and executes both maps in real Chrome; the conflict fixture poisons the root validator so the scoped nested mapping cannot pass accidentally.
The shared host-neutral registry contains 131 unique checks. vanilla-test 2.1.1 executes the same inventory in Node and real Google Chrome.
| Suite | Cases | Focus |
|---|---|---|
| Unit | 16 | Exports, state, fluent identity, validation, and list shape |
| Functional | 26 | Registration, dispatch, wildcard, once, removal, reset, and chaining |
| Integration | 14 | Subclassing, routing, isolation, namespaces, lifecycle, and errors |
| Behavioral | 12 | Given/When/Then workflows, lifecycle boundaries, routing, failures, async effects, and live membership |
| Regression | 43 | Mutation, reentrancy, snapshots, safe names, throws, and registration-local once state |
| Interface | 20 | Playground parsing, safe display, bounded state, benchmark evidence, units, and chart scaling |
| Total | 131 | One registry used by direct tests and both coverage runtimes |
| Verification | Runtime | Hosts | Result requirement |
|---|---|---|---|
| Direct shared suite | Node 22.12.0 and Node 24 | Ubuntu, macOS, Windows | 131/131 on every matrix job |
| Node coverage | Node 24.18.0 | Ubuntu | 131/131 and every native V8 gate at 100% |
| Browser coverage | Google Chrome Stable | Ubuntu | 131/131 and every native V8 gate at 100% |
| Packed consumer | Node 24 | Ubuntu | Exact tarball contents plus ESM/CommonJS execution of nested strong-type 2.0.0 under a poisoned root conflict |
| Packed unbundled browser | Chrome Stable | Ubuntu and local release host | Normal and scoped-conflict import maps execute the tarball directly over HTTP |
| Packed bundled browser | Rollup 4.62.5 + Chrome Stable | Ubuntu and local release host | A bundle resolves nested strong-type 2.0.0 and runs representative behavior under a poisoned root conflict |
| Shared-source package smoke | Node 22.12.0 | Ubuntu | The same packed index.js through ESM import and direct CommonJS require() |
| Execution benchmark | Node 24.18.0 | Ubuntu | Eight validated scenarios with execution-only timing boundaries |
| GitHub Pages | Node 24 | Ubuntu | 22 pages, both runtime reports, badges, benchmark JSON, scripts, links, and licenses |
| Runtime | Executable ranges | Block ranges | Function ranges | Executable lines |
|---|---|---|---|---|
| Node 24.18.0 | 100% | 100% | 100% | 100% |
| Chrome Stable | 100% | 100% | 100% | 100% |
These are native V8 executable/block/function range and executable-line totals for index.js, not parser-derived Istanbul statement or branch counts. Node and Chrome produce independent HTML, JSON, LCOV, and normalized test-result artifacts.
| Command | Purpose |
|---|---|
npm test |
Stage event-pubsub with its nested exact validator and run all 131 checks in Node. |
npm run test:unit |
Run the 16 Unit cases. |
npm run test:functional |
Run the 26 Functional cases. |
npm run test:integration |
Run the 14 Integration cases. |
npm run test:behavioral |
Run the 12 Behavioral scenarios. |
npm run test:regression |
Run the 43 Regression cases. |
npm run test:interface |
Run the 20 Interface cases. |
npm run coverage |
Run all 131 checks independently in Node and real Chrome with 100% gates. |
npm run coverage:node |
Generate only the Node native V8 report. |
npm run coverage:chrome |
Generate only the real-Chrome native V8 report. |
npm run benchmark |
Record seven fixed-count latency samples for eight scenarios. |
npm run benchmark:smoke |
Validate the benchmark quickly without replacing published results. |
npm run test:package |
Pack, inspect, install, and exercise a clean consumer. |
npm run test:browser-consumer |
Pack and execute normal-map, scoped-conflict-map, and Rollup browser consumers in real Chrome. |
npm run site:check |
Validate all focused pages, exact test inventories, scripts, links, forms, and assets. |
npm run verify |
Run the complete local release gate. |
Every test name below is sourced from the shared registry. The focused Pages site presents the same inventory one suite per page.
__proto__ is a safe event nameconstructor is a safe event nametoString is a safe event namehasOwnProperty is a safe event nameThe benchmark reports median execution latency—nanoseconds per named operation—with p25, p75, min, max, and every raw sample. Fixed-count loops use exactly two process.hrtime.bigint() readings around the execution boundary. Dispatch scenarios use distinct minimal observable subscribers, then verify their accumulated effects after timing so empty callbacks cannot become an optimizer-only lower bound. Setup, validation, calibration, warmup, post-run checks, summary work, JSON serialization, file I/O, Node startup, and CI orchestration are excluded. The charts never present total benchmark or workflow duration as module execution time.
require() of the native ESM source.event-pubsub and strong-type from package metadata normally.Symbol, and import maps; no build step is required. Map both package names, with a scoped validator mapping when npm nests it.MIT. See licence.
© 2010 - cnpmjs.org x YWFE | Home | YWFE