Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mvaldesdeleon/ezp
Easy Proxy for fluent APIs
https://github.com/mvaldesdeleon/ezp
Last synced: about 6 hours ago
JSON representation
Easy Proxy for fluent APIs
- Host: GitHub
- URL: https://github.com/mvaldesdeleon/ezp
- Owner: mvaldesdeleon
- License: other
- Created: 2018-10-03T12:38:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-07T20:25:50.000Z (about 6 years ago)
- Last Synced: 2024-11-07T23:41:28.248Z (9 days ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ezp
Easy Proxy for fluent APIs.
# Use
```js
const ezp = require('ezp');const P = ezp({
get: function(props) {
// Called by:
// P.foo.bar.baz.$
// props:
// ['foo', 'bar', 'baz']
},
set: function(props, value) {
// Called by:
// P.foo.bar.baz = 1337
// props:
// ['foo', 'bar', 'baz']
// value:
// 1337
},
delete: function(props) {
// Called by:
// delete P.foo.bar.baz;
// props:
// ['foo', 'bar', 'baz']
},
has: function(props) {
// Called by:
// 'qux' in P.foo.bar.baz
// props:
// ['foo', 'bar', 'baz']
// value:
// 'qux'
},
apply: function(props, args) {
// Called by:
// P.foo.bar.baz(1337, 'qux')
// props:
// ['foo', 'bar', 'baz']
// args:
// [1337, 'qux']
},
}, '$');
````ezp` receives a handler object and an optional escape property, and returns a fluent proxy.
The handler object supports the following fluent traps: `get`, `set`, `delete`, `in` and `apply`, which are triggered as illustrated in the example above.
Note that to use the `get` trap, an escape property must be provided. This value will then be *magical*, and be used to trigger the `get` trap instead of navigating one level deeper within the proxy itself.
**NOTE:** The proxy is created as a *virtual object*, and interacting with the underlying target without setting the appropriate traps may result in unspecified behaviour. Use only the proxy in ways which are handled by the traps provided.
# Install
with [npm](https://npmjs.org) do:```sh
npm install ezp
```# License
MIT