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

@latostadora/rayjs

v0.10.2

Published

`ray.js` is a library that checks the DOM for html components and execute its related js counterpart

Readme

Ray.JS

ray.js is a library that checks the DOM for html components and execute its related js counterpart

alt tag

Table of contents

  1. Installation
  2. An overview
  3. Errors
  4. Commands
  5. More examples

Installation

Just download ray.js and load it in your page

or use this:

<script type="text/javascript" src="https://raw.githubusercontent.com/Latostadora/rayjs/master/dist/ray-min.js"></script>

then, when your are ready to start looking for components, execute this:

<script type="text/javascript">
    new Ray().begin();
</script>

An overview

When de DOM is ready Ray.js checks the DOM for elements with the data-ray-component attribute and executes the js that indicates the value of this attribute (Example 1). You can add data-ray-params attribute with value on JSON format (Example 2).

Example:

Let's suppose we have this html (note the data-ray-component attribute)

    <img data-ray-component="ChangeImageSrcComponent" src="images/test1.jpg">

Also, you can load multiple components like this:

    <img data-ray-component="ChangeImageSrcComponent,SimpleImageComponent" src="images/test1.jpg">

the JS part of this component changes the src when it's executed:

    window.ChangeImageSrcComponent=function(data) {
        var image=data.DOMElement;
        image.setAttribute("src","images/test2.jpg");
    };

For a more complex example check the samples directory

Data object

On every execution an component ray.js injects a data object containing 3 properties:

  • DOMElement: a reference to the DOMElement that triggers the execution of the component
  • bus: a reference to an EventBus
  • params: a reference to params added in DOM Element like data-ray-params in JSON
  • If you have multiple components the data object is shared for all of them

Bus

The ray.js bus has two methods:

  • trigger(eventName, eventPayload) triggers an event with the corresponding payload
  • on(eventName, callbackFn) listen to an event an sets the callback function to be called when the event happens

data-ray-params attribute

The data-ray-params attribute allows to inject JSON formatted params (it must be valid JSON or it will fail)

Let's suppose we have this html (note the data-ray-params attribute)

    <img data-ray-component="ChangeImageSrcComponent" data-ray-params='{"srcImage":"images/test2.jpg"}' src="images/test1.jpg">

the JS part of this component receives the params property on the data object:

    window.ChangeImageSrcComponent=function(data) {
        var image = data.DOMElement;
        var src = data.params.srcImage;
        image.setAttribute("src",src);
    };

Errors

ray.js throws an Ray.Events.ERROR event on the EventBus if it detects an Error with the Exception as the payload. You can catch the error with this sample code:

    ray.bus.on(Ray.Events.ERROR, function(exception) {
        console.log("Error:"+exception.message);
    };

Commands

You can send a command to the ray.js bus to search & execute new components:

    ray.bus.trigger(Ray.Commands.EXECUTE_NEW_COMPONENTS);

More examples

You can check more complex examples in the samples directory