UNPKG

obj-chain-core

Version:

fluent chaining for obj with dot-prop access

24 lines (23 loc) 630 B
module.exports = function ProxyPlugin(ObjChain) { // eslint-disable-next-line /** * @tutorial http://thecodebarbarian.com/thoughts-on-es6-proxies-performance.html * @description dynamically adds properties when called if they do not exist * @see ObjChain.init * @param {string | Object} data json data * @return {JSONChain} */ return { dynamic(data) { const target = new ObjChain(data) return new Proxy(target, { get(thisArg, name) { if (!(name in thisArg)) { thisArg.extend([name]) } return thisArg[name] }, }) }, } }