New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-proxy

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-proxy

Use ES2015 proxies today!

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
225
decreased by-42.31%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-proxy

JavaScript Style Guide

Use ES6 proxies today!

Installation

npm install babel-plugin-proxy --save-dev

Motivation

Proxies are awesome feature of ES2015 that enables redefining some language operations. For example we can intercept every object property access with our own function.

The problem is that proper proxy implementation requires native browser support (currently it works in Firefox and Edge). This plugin is proof of concept that proxies can be implemented with ES5 features. It is not suitable for production environments because performance impact is huge.

How does it work?

We are intercepting every property access (except these connected with function invocation) and property assignment with custom interceptor functions that performs runtime check if object is proxied.

proxy.foo = 5;
proxy.foo;
   

becomes:

globalSetInterceptor(proxy, "foo", 5);
globalGetInterceptor(proxy, 'foo');

These interceptors performs runtime check if object should be proxied. You can check out whole runtime here

Example

Proxies for example allow us to create objects that will warn us when undefined key is being accessed.

var proxy = new Proxy({}, {
    get: function(target, propKey) {
        if (!(propKey in target)) {
            console.log("Accessing undefined key!");
        }

        return target[propKey];
    }
});

proxy.a = 5;
console.log(proxy.a);
console.log(proxy.b);

output:

5
Accessing undefined key!
undefined

FAQs

Package last updated on 29 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc