2.0.1 • Published 8 months ago

@rook2pawn/picobus v2.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

šŸšŽ picobus

https://github.com/rook2pawn/picobus A lightweight, dependency-free event emitter for JavaScript and Node.js. Ideal for managing state transitions, building FSMs, and wiring up simple pub/sub flows.

Published on npm as @rook2pawn/picobus https://www.npmjs.com/package/@rook2pawn/picobus

Features

āœ… Simple .on(event, fn) and .emit(event, data) interface

āœ… .once() support for one-time listeners

āœ… .off() and .removeAll() for cleanup

āœ… Wildcard * event support

āœ… Tiny and fast (zero dependencies)

Installation

npm install picobus

Testing

npm test

Usage

import { PicoBus } from 'picobus';

const bus = new PicoBus();

function onFoo(data) {
  console.log('Got foo:', data);
}

bus.on('foo', onFoo);

bus.emit('foo', { msg: 'hello' });
// => Got foo: { msg: 'hello' }

bus.off('foo', onFoo);
bus.emit('foo', { msg: 'world' }); // no output

API

bus.on(event, fn)

Register a listener for a specific event.

bus.once(event, fn)

Register a listener that fires only once.

bus.off(event, fn)

Remove a specific listener for a given event.

bus.emit(event, data)

Emit an event and pass optional data.

bus.removeAll(event?)

Remove all listeners for an event. If no event is specified, removes all listeners for all events.

bus.on('*', fn)

Wildcard support: catch all emitted events.

bus.on('*', (eventName, data) => {
  console.log(`[${eventName}] ->`, data);
});

License

MIT 2025

2.0.1

8 months ago

2.0.0

8 months ago