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

ecco-proxy

v0.0.5

Published

Helper for proxing objects in JS

Readme

EccoProxy

A helper to proxy object in JS.

Intro

EccoProxy allows you to interact with existing object. You'll be able to:

  • 🚀 trigger side effects on method and property calls
  • 🎸 manipulate methods' arguments
  • 🥾 overwrite methods and properties
  • 📝 validate properties before setting them

Here's a sandbox to play with.

Setup

yarn add ecco-proxy

or

npm install ecco-proxy

Usage

import { EccoProxy } from "ecco-proxy";

const proxiedObject = EccoProxy(
    myObject,
    // ⬇️ GET - manipilate what happens when methods and props are invoked 
    {
        methodName: (receivedArguments, originalMethod, originalObject) => {},
        propertyName: (originalValue, originalObject) => {},
    },
    // ⬇️ SET - manipilate what happens when methods and props overwritten
    {
        otherPropertyName: (receivedValue, setValue) => {}
    });

Examples

Intercepting and add manipulating 'console' methods

Let's imagine you want to make sure that the all the logs of your application get stored in your remote server.

This is how you would do it with EccoProxy:

import { EccoProxy } from "ecco-proxy";

const proxiedConsole = EccoProxy(window.console, {
  error: (receivedArguments, originalMethod) => {
    // trigger side effects
    shipToServer(receivedArguments);
    
    // manipulate arguments
    const prettyErrors = receivedArguments.map(makePretty);
    
    // let the original library do its stuff, with the manipulated args
    return originalMethod(...prettyErrors);
  },
});

// now just use this module instead of the original when logging stuff
window.console = proxiedConsole

Dynamically react to property changes

Let's imagine you want to know when a property of an object changes, to trigger some side effect. Here's how you can do it.

import { EccoProxy } from "ecco-proxy";

const store = {
    data: "content"
};

const proxiedStore = EccoProxy(store, {}, {
    data: (receivedValue, setValue) => {
        // whenever the store.data gets changed, trigger our custom callback
        triggerCallback(receivedValue);

        // apply the new value
        setValue(receivedValue);

        // return true to indicate success
        return true;
    }
})

export { proxiedStore as store }

Add validation to property set

Let's say we have an object with some property that we do not want to mutate. Here's how to do it

import { EccoProxy } from "ecco-proxy";

const store = {
    maxSize: 100
};

const proxiedStore = EccoProxy(store, {}, {
    maxSize: (receivedValue, setValue) => {
        const number = Number(receivedValue);
        if (isNaN(receivedValue) || !Number.isInteger(number) || number < 0) {
            console.error("store.maxSize has to be a integer, positive number")
            return false;
        }

        // otherwise set the number
        setValue();

        // return true to indicate success
        return true;
    }
})

export { proxiedStore as store }

Prevent certain properties or methods from being changed

Let's say we have an object with some property that we do not want to mutate. Here's how to do it

import { EccoProxy } from "ecco-proxy";

const store = {
  id: "IDXXX"   
};

const proxiedStore = EccoProxy(store, {}, {
    id: () => {
        console.error("You cannot change the ID of a store")
        
        // do not set any value
        
        // return false to indicate failure
        return false;
    }
})

export { proxiedStore as store }