All Projects → samvv → Js Proxy Deep

samvv / Js Proxy Deep

Licence: mit
A proxy API for deeply nested JavaScript objects

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Js Proxy Deep

Chromesnifferplus
🔍 Sniff web framework and javascript libraries run on browsing website.
Stars: ✭ 788 (+2617.24%)
Mutual labels:  javascript-library
Jsmlt
🏭 JavaScript Machine Learning Toolkit
Stars: ✭ 22 (-24.14%)
Mutual labels:  javascript-library
Sketch
Just a HTML5 sketch-pad.
Stars: ✭ 9 (-68.97%)
Mutual labels:  javascript-library
Spotlight
Web's most easy to integrate lightbox gallery library. Super-lightweight, outstanding performance, no dependencies.
Stars: ✭ 799 (+2655.17%)
Mutual labels:  javascript-library
Wykop Es6
Wykop.pl API library
Stars: ✭ 17 (-41.38%)
Mutual labels:  javascript-library
React Spaces
React components that allow you to divide a page or container into nestable anchored, scrollable and resizable spaces.
Stars: ✭ 928 (+3100%)
Mutual labels:  javascript-library
Msgpack Javascript
MessagePack for JavaScript/TypeScript/ECMA-262 / msgpack.org[JavaScript]
Stars: ✭ 742 (+2458.62%)
Mutual labels:  javascript-library
Oojs
Power for object oriented javascript libraries. This is a mirror from https://gerrit.wikimedia.org. See https://www.mediawiki.org/wiki/Developer_access for contributing.
Stars: ✭ 14 (-51.72%)
Mutual labels:  javascript-library
Elfi
An elegant state container for your JavaScript applications
Stars: ✭ 18 (-37.93%)
Mutual labels:  javascript-library
Waff Query
Lightweight DOM manager
Stars: ✭ 9 (-68.97%)
Mutual labels:  javascript-library
Infinite Ajax Scroll
Turn your existing pagination into infinite scrolling pages with ease
Stars: ✭ 804 (+2672.41%)
Mutual labels:  javascript-library
Thread
Simply, lightweight and easy multi-thread JavaScript library
Stars: ✭ 17 (-41.38%)
Mutual labels:  javascript-library
Graphicsjs
A lightweight JavaScript graphics library with the intuitive API, based on SVG/VML technology.
Stars: ✭ 937 (+3131.03%)
Mutual labels:  javascript-library
Trip.js
🚀 Trip.js is a plugin that can help you customize a tutorial trip easily with more flexibilities.
Stars: ✭ 789 (+2620.69%)
Mutual labels:  javascript-library
Termynal
⬛️ Lightweight and modern terminal animations using async/await
Stars: ✭ 858 (+2858.62%)
Mutual labels:  javascript-library
Nativeshare
NativeShare是一个整合了各大移动端浏览器调用原生分享的插件
Stars: ✭ 751 (+2489.66%)
Mutual labels:  javascript-library
Psd Guides
📐 JS library to draw photoshop-like guides.
Stars: ✭ 22 (-24.14%)
Mutual labels:  javascript-library
Zumly
Zumly is a JS library for building zooming user interfaces
Stars: ✭ 22 (-24.14%)
Mutual labels:  javascript-library
Flexsearch
Next-Generation full text search library for Browser and Node.js
Stars: ✭ 8,108 (+27858.62%)
Mutual labels:  javascript-library
Validformbuilder
ValidForm Builder. Easy and safe XHTML 1.0 strict forms with validation!
Stars: ✭ 26 (-10.34%)
Mutual labels:  javascript-library

This is a library which enables users to "trap" deeply nested objects into proxies. The API is identical to the proxy API, except that traps get an additional this context with a method for nesting the current proxied object into a deeper one.

✨ Now updated with support for TypeScript! See the change log for more information.

Examples

A simple example for DSL language building:

const DeepProxy = require('proxy-deep');

const db = new DeepProxy({}, {
  get(target, path, receiver) {
    return this.nest()
  },
  apply(target, thisArg, argList) {
    return this.path;
  }
})

console.log(db.select.from.where()) // outputs ['select', 'from', 'where']

Another example using Node's process object:

const DeepProxy = require('proxy-deep')
const { EventEmitter } = require('events')

const emitter = new EventEmitter()

const pp = DeepProxy(process, {
  get(target, key, receiver) {
    const val = Reflect.get(target, key, receiver);
    if (typeof val === 'object' && val !== null) {
      return this.nest({})
    } else {
      emitter.emit('access', this.path)
      return val
    }
  }
})

emitter.on('access', path => {
  console.log(`${path} was accessed.`)
})

pp.argv[0] // trapped!

API

new DeepProxy(target, handlers, [options])

Identical to new Proxy(target, handlers), except that the callbacks provided in the traps object will be called wiith a this-context that has some additional properties. For a full reference on what arguments are provided to the handlers, please consult the a MDN web docs.

options is an object that can contain the following entries:

  • path either a string denoting the full path to the object or an array of property keys

this.rootTarget

A reference to the object with wich the deep proxy was created.

this.path

Holds the full property path to the given object.

this.nest([nestedTarget])

Returns a new proxy that will trap methods as described in this API. nestedTarget is an optional object with which the proxy will be initialized. If it is not specified, the target that was passed to new DeepProxy() will be used.

handler.getPrototypeOf()

A trap for Object.getPrototypeOf.

handler.setPrototypeOf()

A trap for Object.setPrototypeOf.

handler.isExtensible()

A trap for Object.isExtensible.

handler.preventExtensions()

A trap for Object.preventExtensions.

handler.getOwnPropertyDescriptor()

A trap for Object.getOwnPropertyDescriptor.

handler.defineProperty()

A trap for Object.defineProperty.

handler.has()

A trap for the in operator.

handler.get()

A trap for getting property values.

handler.set()

A trap for setting property values.

handler.deleteProperty()

A trap for the delete operator.

handler.ownKeys()

A trap for Object.getOwnPropertyNames and Object.getOwnPropertySymbols.

handler.apply()

A trap for a function call.

handler.construct()

A trap for the new operator.

License

The MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].