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

@hxss/recursive-proxy

v1.0.3

Published

This is like native ES6 Proxy but recursive. Native syntax. Native functional multiplied by recursiveness.

Downloads

5

Readme

RecursiveProxy.js

This is like native ES6 Proxy but recursive. Native syntax. Native functional multiplied by recursiveness.

Unlike other similar projects this class using only 2 js Proxies for traverse over your object. No new Proxy every time you need to get regular field.

Usage

var proxy = new RecursiveProxy(object[, handler = {}]);

As with original Proxy you can override any of traps:

this.traps = [
	'apply',
	'construct',
	'defineProperty',
	'deleteProperty',
	'enumerate',
	'get',
	'getOwnPropertyDescriptor',
	'getPrototypeOf',
	'has',
	'isExtensible',
	'ownKeys',
	'preventExtensions',
	'set',
	'setPrototypeOf'
];

...with native syntax, but as first argument this traps will receive current target instead of original, that you specify in constructor.

And 2 new methods used by RecursiveProxy getter:

  • isObject(val) - return true|false. Used for detect if this field object that we can use as new target or this is just value that we send in traditional getter. By default return val.constructor.name === 'Object';(only basic Object can be used as sub target);
  • getObject() - used for return Proxy object when we dive in new object. Doesn't get any argument but as any other traps run in context of RecursiveProxy object and has access to all its fields.

RecursiveProxy fields

Every trap-method specified in handler can use any of this fields:

  • this.target - original target. Object that you use in constructor.
  • this.curTarget - current target. Sub object that now using as target for Proxy.
  • this.path - array-path that contain name of every opened branch of original target.
  • this.p0 - zero-point Proxy that using only with original target.
  • this.proxy - recursive Proxy that using for access to any sub target. This is the proxy that by default return by getObject method.

Examples

const s = {
	a: {
		b: {
			c: {
				d: 'ddd',
			},
			custom: new CustomObject(),
		},
		z: 'zzz',
	},
};

var rp = new RecursiveProxy(s, {
	get: function(target, prop, receiver) {
		console.log('get:', prop);
		return Reflect.get(...arguments);
	},
	getObject: function() {
		console.log('getObject:', this.path);
		return this.proxy;
	},
});

console.log('val:', rp.a.b.c.d);

outputs:

getObject: ["a"]
getObject: ["a", "b"]
getObject: ["a", "b", "c"]
get: d
val: ddd

console.log('val:', rp.a.b.custom);

outputs:

getObject: ["a"]
getObject: ["a", "b"]
get: custom
val: CustomObject {}