@rook2pawn/picobus v2.0.1
š 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 picobusTesting
npm testUsage
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 outputAPI
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