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

recursive-proxy

v1.1.0

Published

JS Recursive proxy.

Downloads

46

Readme

recursive-proxy

Quite like native ES6 proxy, but recursive!

Installation

yarn add recursive-proxy

or via NPM

npm install --save recursive-proxy

Examples

For more details on how does it work check examples folder.

To run examples type

yarn babel-node -- example/gets.js

or

yarn babel-node -- example/observer.js

Usage

import RProxy from 'recursive-proxy';

const target = {}; // proxy target

const context = {/* context */};


const proxyConfig = {
    // Options
    
    // Whether apply (follow) proxy on nested functions
    // bool, default: true
    followFunction: true,
    
    // Whether apply (follow) proxy on nested arrays
    // bool, default: false
    followArray: false,
    
    // Whether apply (follow) proxy on nested, non plain objects
    // bool, default: true
    followNonPlainObject: false,
    
    // Whether proxy should be readOnly
    // values: "error", "silent", false (default)
    readOnly: false,
    
    // Recursive path separator
    // string, default: "."
    pathSeparator: '.',
    
    // Traps
    
    // Each trap definition is an object with path expression as
    // a key and trap specific value or callback. Every callback 
    // function has context bound as this
    
    // Path expression (PE) starts with pathSeparator character (PS)
    // after which (PS) separated path is provided.
    // ex. ".a" is property "a" of target object
    // ex. ".a.b" is property "b" of "a" object of target 
    //
    // Wildcards when (PE) doesn't start with (PS) and there was no 
    // exact path match it can be matched to the property name itself 
    // ex. "a" is property "a" of target object or any of its nodes
    //
    // When there is no wildcard match "" (empty) path is considered
    // as fallback (if present).
    
    // Replace value with provided static value
    value: {
        // (PE): value to be returned for that property
    },
    
    // Replace value with value computed from callback
    // currentValue may come from value trap 
    creator: {
        // (PE): (currentValue, target, propName, pathToTrappedItem) => newValue
    },
    
    // Trap when prop value is changed
    setter: {
        // (PE): (target, propName, newValue, pathToTrappedItem) => changeWasAllowed?
    },
    
    // Trap when target is a function and is called
    apply: {
        // (PE): (target, this, argsArray, pathToTrappedItem) => anyValue
    },
    
    // Trap when target is a function and is called with "new" operator
    construct: {
        // (PE): (target, argsArray?, newTarget, pathToTrappedItem) => object
    }
};

const proxy = RProxy(proxyConfig, target, context);
// or with new operator
const proxy = new RProxy(proxyConfig, target, context);