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

waject

v2.0.0

Published

JavaScript library for managing state.

Downloads

3

Readme

What is a Waject?

waject() is a JavaScript library for managing state.

The waject constructor has extensions that may be defined to add functionality to future calls to waject. Extensions do not affect wajects created prior to an extension definition.

Purpose

waject is an extendable function that converts a target object into a proxy. The returned proxy may then be used to listen for changes on get or set occurrences.

Listening on set occurrences is useful:

  • for keeping HTML elements in sync with objects.
  • for keeping server-side objects in sync with client-side objects.
  • for objects which contain data that, when changed, should have side-effects on other data in the same object or outside of the object.

Listening on get occurrences is useful:

  • for data that is built using an algorithm.

Syntax

waject(target)

Parameters

Objecttarget

A target object to wrap with Proxy. It can be any sort of object, including a native array, a function or even another proxy.

Return value

A newly created Proxy with all defined extensions attached.

Example:
// Create a waject
let example = waject({
    message: "hello, world"
});

// Listen for "set" change on "message"
example.on("set", "message", result => {
    console.log(property, "changed to", result.value);
});

// Change "message", triggering a "set" occurrence
example.message = "Goodnight";
// console logs "message changed to Goodnight"

console.log(example.message); // "Goodnight"

Traps

The returned proxy has a get trap and a set trap.

Both traps follow this order of interception:

  • Extensions are intercepted first.
    • get will return the extension function, bound to the waject instance.
    • set will return false, and log a warning:
      • Waject: Ignoring set to '${prop}' property, because it's an extension.
  • "*" property is intercepted second. * represents all.
    • Extensions named * will override this functionality.
    • get will return a static copy of the target object, with every get listener resolved.
    • set will do one of two things:
      • If the value is a compatible object:
        • Assign each value of the compatible object to the target object.
      • If the value is a non-object, or non-compatible object:
        • Assign each property of the target to the new value.
  • Any other property.
    • get
      • Default value to target[key]
      • Cycle through get listeners bound to key
      • Cycle through get listeners bound to all properties.
      • Return value.
    • set
      • Cycle through set listeners bound to key
      • Cycle through set listeners bound to all properties.
      • Set target[key] to value and return it.

Extensions

Extensions are used to add non-enumerable, non-configurable methods bound to future waject instances.

Internally, extensions are stored in an object, extensions, with the interceptProperty as the property name, and the extension's function as the value bound to a waject instance.

Source code:

    let extensions = {};

    for (let interceptProperty in this.constructor.extensions) {
        extensions[interceptProperty] = this.constructor.extensions[interceptProperty].bind(this);
    }

[[waject]].on(Stringgroup,(Stringproperty,)Functioncallback)