https://github.com/slikts/deepproxy
Recursive ES2015 Proxy
https://github.com/slikts/deepproxy
es2015 es2015-proxy library proxy recursion
Last synced: 4 months ago
JSON representation
Recursive ES2015 Proxy
- Host: GitHub
- URL: https://github.com/slikts/deepproxy
- Owner: slikts
- License: mit
- Created: 2018-08-05T14:14:19.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-05T17:04:56.000Z (almost 8 years ago)
- Last Synced: 2025-08-08T22:30:56.989Z (10 months ago)
- Topics: es2015, es2015-proxy, library, proxy, recursion
- Language: TypeScript
- Size: 190 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Deep `Proxy`
[](https://travis-ci.org/slikts/deepproxy)
[](https://coveralls.io/github/slikts/deepproxy)
A tiny library to recursively wrap an object and all its sub-objects with [ES2015 `Proxy`][Proxy].
## Installation
```
npm install --save @slikts/deepproxy
```
## Usage
```js
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
[Proxy]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy