@slikts/deepproxy
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Deep Proxy

Travis Coveralls

A tiny library to recursively wrap an object and all its sub-objects with ES2015 Proxy.

Installation

npm install --save @slikts/deepproxy

Usage

import { deepProxy } from "@slikts/deepproxy"

const a = deepProxy({ b: { c: 1 } }, {
  get(target, key) {
    return target[key] ? target[key] : 123;
  }
});

a.b; // -> { c: 1 }
a.foo; // -> 123
a.b.c; // -> 1
a.b.foo; // -> 123

How it Works

The target object is wrapped with an additional Proxy that traps property access and also wraps any values of object type. The created proxies are memoized to avoid re-creating them for the same target and handler.

License

MIT

Author

slikts dabas@untu.ms

Dependents (0)

Package Sidebar

Install

npm i @slikts/deepproxy

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

43.1 kB

Total Files

10

Last publish

Collaborators

  • slikts