Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-proxy

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-proxy

Make proxies work with arrays.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Array proxy

Description

JavaScript proxy objects don't work with arrays because they have native properties that are not proxied. This library make them work.

Usage


const { arrayHandler } = require('array-proxy')

const handler = {
  get: (target, prop, receiver) => {
    if (prop === 'foo') {
      return 'bar'
    }
    return Reflect.get(target, prop, receiver)
  }
}
const newHandler = arrayHandler(handler)

const nativeProxy = new Proxy([42], handler)
const arrayProxy = new Proxy([42], newHandler)

console.log(nativeProxy.foo)
// => bar
console.log(nativeProxy.forEach(e => console.log(e)))
// => throws
//    Uncaught TypeError: Method Array.prototype.forEach called on incompatible receiver #<Array>
//        at Proxy.forEach (<anonymous>)

console.log(arrayProxy.foo)
// => bar
arrayProxy.forEach(e => console.log(e))
// => 42


API

arrayHandler(handler)

The input is a proxy handler.

Returns a new proxy handler which wraps the input in a handler which make proxies work with arrays.

FAQs

Package last updated on 18 Jan 2022

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