JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 21207
  • Score
    100M100P100Q127612F
  • License MIT

A proxy for deep objects

Package Exports

  • proxy-deep

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (proxy-deep) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

This is a library which enables users to "trap" deeply nested objects into proxies. The API is identical to the proxy API, except that keys are now paths in the object, and that a special nest()-procedure is added to the get-trap as a parameter.

A simple example using Node's process object:

const proxyDeep = require('proxy-deep')
const _ = require('lodash')
const { EventEmitter } = require('events')

const emitter = new EventEmitter()

const pp = proxyDeep(process, {
  get(p, path, nest) {
    const val = _.get(p, path)
    if (typeof val !== 'object') {
      emitter.emit('access', path)
      return val
    } else {
      return nest()
    }
  }
})

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

pp.argv[0] // trapped!