Preserved
on, once, off, emit, reset, live wildcard-first execution, default/named exports, the unified registry, and its Symbol wildcard bucket.
Migration · 5.x → 6.x
The familiar five methods remain. Version 6 tightens runtime support and fixes edge behavior around one-shot handlers, registry mutation, chaining, and list isolation.
Production and repository development use Node.js 22.12.0 or newer so ESM imports and direct CommonJS require() share the same source.
npm install event-pubsub@6Version 6.1.1 is the current npm release.
import EventPubSub, { EventPubSub as Named } from 'event-pubsub';
const Required = require('event-pubsub');Both module systems load the same native ESM implementation. The historical index.js entry remains available without a restrictive export map.
emit remains fluent as it was in 5.x. One-shot state no longer mutates handler functions. Live arrays still allow newly appended handlers to run in the current dispatch. Specifically removed handlers are skipped before their turn; removing a whole bucket detaches it from future lookup while an already-active array finishes.
list as a snapshotEach access returns a null-prototype object with copied handler arrays. Mutating or deleting values in that snapshot no longer changes the live registry. Use Object.hasOwn(snapshot, type) instead of snapshot.hasOwnProperty(...).
Pay special attention to code that depended on undocumented handler symbols, shared list arrays, or mutation during an active dispatch.
Bundlers need no import-map setup. Native browser ESM does: put this map before the first module script, serve over HTTP(S), and expose the mapped files. The 6.1.1 README also shows the scoped map required for a conflicting root validator.
<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>If the app uses a strict CSP, authorize the inline import-map and module scripts with an allowed nonce or hash.
on, once, off, emit, reset, live wildcard-first execution, default/named exports, the unified registry, and its Symbol wildcard bucket.
strong-type 2.0.0 remains the sole production dependency. The 6.1.1 entry uses its bare package name so Node selects event-pubsub's nested exact copy under a root conflict. Bundlers resolve both names normally; unbundled native ESM uses an import map with no build step and scopes the validator to event-pubsub when nested. copyfiles, c8, and the old test-only server remain absent.