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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tiny-observable

v2.0.2

Published

Tiny Observable for Client and Server

Readme

Tiny Observable

Tiny Observable for Client or Server, to be used with DOM elements or custom objects.

Using the factory

import {observable} from "tiny-observable";
const observer = observable();

// Hooking into every click event
observer.hook(document.querySelector("body"), "click");

// Capturing events, and redirecting
observer.on("click", ev => customFunction(ev));

Using the Class

import {Observable} from "tiny-observable";
const observer = Observable();
import {Observable} from "tiny-observable";
class MyObservable extends Observable {}

Testing

Tiny Observable has 100% code coverage with its tests.

> nyc mocha test/*.js



  Observable
    √ Will create a new observable
    √ Will reassign limit with setMaxListeners()
    √ Will dispatch events when empty
    √ Will hook element dispatch of event
    √ Will dispatch event
    √ Will unhook element dispatch of event
    √ Will add & remove event handlers to a hooked input
    √ Will throw errors with bad inputs


  8 passing (6ms)

---------------------|---------|----------|---------|---------|---------------------------------------
File                 | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------|---------|----------|---------|---------|---------------------------------------
All files            |   95.83 |    76.71 |   86.95 |     100 |                                      
 tiny-observable.cjs |   95.83 |    76.71 |   86.95 |     100 | 18-24,38,58,63,89,114,127-139,154-155
---------------------|---------|----------|---------|---------|---------------------------------------

API

addListener(event, handler[, id, scope])

Adds a listener for an event.

dispatch(event [, ...]);

Dispatches an event, with optional arguments.

emit(event [, ...]);

Dispatches an event, with optional arguments.

eventNames();

Returns an Array of event names.

getMaxListeners();

Returns the limit of listeners per event.

listenerCount(event);

Returns the count of listeners per event; this does not relate to hooked objects or elements.

hook(object, event);

Hooks an event on an object or element.

id();

Returns a random ID.

off(event, id);

Removes all, or a specific listener for an event.

on(event, handler[, id, scope])

Adds a listener for an event.

once(event, handler[, id, scope])

Adds a single execution event listener for an event.

rawListeners(event)

Returns an Array of raw functions for an event.

removeAllListeners(event)

Removes all event listeners for an event.

removeListener(event, id)

Removes an event listener by id.

setMaxListeners(n);

Sets the limit of listeners per event.

unhook(object, event);

Unhooks an event from an object or element.

License

Copyright (c) 2023 Jason Mulligan Licensed under the BSD-3 license