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 🙏

© 2024 – Pkg Stats / Ryan Hefner

oseventlistener

v1.0.6

Published

A simple modern a strong typed javascript library to subscribe, manage and dispatch events

Downloads

26

Readme

Build Status npm version Coverage Status Donations via PayPal

OSEventListener

A simple Typescript/VanillaJS Event Listener

Why choose OS Event Listener?

  • It is modern, code written in Typescript with ES2020 target and ES Modules.
  • It is simple to use.
  • It is cross compatible, it works in any browser with at least ES2015 support, NodeJs and more.
  • It is modular, it supports AMD, UMD, CommonJS, SystemJs module loading systems.
  • Works very well in a browser without any deps or tools, because it provides an iife browser bundle that exposes the library on window ready to be used.
  • It is strong typed, thanks to Typescript it provides type definitions, there is no use of "any" type.
  • It is advanced, the behavior can be changed with custom options covering most of use cases.

How to load it

You can check samples here: https://github.com/OrbintSoft/OSEventListener/blob/master/sample

If you checkout the git project you can run npm run server, to start a simple server and test the varius module loading.

Below the supported module loading systems

AMD: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/amd.html

UMD: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/umd.html

System.JS: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/system.html

Browser / IIFE Bundle: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/bundle.html

ES6: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/es.html

NodeJs / CommonJS: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/node_sample.cjs

NodeJs / ES module: https://github.com/OrbintSoft/OSEventListener/blob/master/sample/node_sample.mjs

How to use:

Create an Event

const event = new EventListener('name');

Subscribe to an event

const fn = (sender, data) => {
	console.log(data);
};
event.subscribe(fn);

Subscribe with key

event.subscribeWithKey((sender, data) => {
	console.log(data);
}, 'logdata');

Unsubscribe to an event

event.unsubscribe(fn);

Unsubscribe with key

event.unsubscribeWithKey('logdata');

Dispatch an event

event.dispatch(this, 'my data');

Documentation

For detailed doc, check here: