npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ouroboros/events

v1.1.3

Published

Package to give the ability to subscribe to and trigger synchronous events in javascript. Useful for passing data around a project without creating import conflicts.

Readme

@ouroboros/events

npm version MIT License

A library to give the ability to subscribe to and trigger synchronous events in javascript. Useful for passing data around a project without creating import conflicts / circular dependencies.

Installation

npm

npm install @ouroboros/events

Getting Started

Import events into your code

import events from '@ouroboros/events';

Subscribing and unsubscribing in a React useEffect hook:

export default function App() {
  useEffect(() => {
    const headerClick = (element) => {
      alert(`Header ${element} element was clicked!`)
    }
    events.get('header').subscribe(headerClick);
    return () => {
      events.get('header').unsubscribe(headerClick');
    }
  }, []);

  return (
    <Header />
  )
}

It is not required to name or store your callbacks, as subscribe will also return an object with an unsubscribe function, making the following effectively the same as above.

function ElementClick({ }) {
  const [ element, setElement ] = useState(false);
  useEffect(() => {
    const e = events.get('header').subscribe(setElement);
    return () => {
      e.unsubscribe();
    }
  }, []);
  if(!element) {
    return null;
  }
  return <span>Header {element} element was clicked!</span>
}

Triggering an event from another component:

export default function Header(props) {
  return (
    <div onClick={() => {
      events.get('header').trigger('div');
    }}>
      <p onClick={() => {
        events.get('header').trigger('p');
      }}>Header Content</p>
    </div>
  );
}

Immediate triggers

If you ever run into the issue of triggers being fired off before your component is able to subscribe, you can use lastArgs, the last set of arguments to trigger, via the return from subscribe.

  useEffect(() => {
    const e = events.get('header').subscribe(setElement);
    if(e.lastArgs !== null) {
      setElement(e.lastArgs[0]);
    }
    return () => {
      e.unsubscribe();
    }
  }, []);

Triggering

The trigger function has no set number of arguments, but instead excepts a variable length of them, all of which will be passed to any subscription callback. This works in JavaScript because it's up to you if you want to use the data or not.

For example, we could change the above example to the following

export default function Header(props) {
  return (
    <div onClick={() => {
      events.get('header').trigger('div');
    }}>
      <p onClick={() => {
        events.get('header').trigger('p', 'div');
      }}>
        <b onClick={() => {
          events.get('header').trigger('b', 'p', 'div');
        }}>Header Content</b>
      </p>
    </div>
  );
}

And our original callback with only one argument would still work without issue, but if you ever wanted to extend it, you could add a second variable to store the parent:

  useEffect(() => {
    const e = events.get('header').subscribe((element, parent) => {
      if(parent) {
        alert(`Header ${element} of ${parent} was clicked!`)
      } else {
        alert(`Header ${element} element was clicked!`)
      }
    });
    return () => {
      e.unsubscribe();
    }
  }, []);

...or switch completey to your own variable length callback.

  useEffect(() => {
    const e = events.get('header').subscribe(() => {
      const reverse = arguments.slice().reverse();
      alert(`Header ${reverse.join(' -> ')} element was clicked!`)
    });
    return () => {
      e.unsubscribe();
    }
  }, []);