Created
February 13, 2020 12:09
-
-
Save v1vendi/b87ad119e12b5fab9da43ffda8f5f7cb to your computer and use it in GitHub Desktop.
Revisions
-
v1vendi created this gist
Feb 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ const model = { normalKey: 1, coRRupTkey: 2, innErKey: { x: 3, Y: 4 }, aRR: [ { first: 5 } ] } function getModel(model) { return new Proxy(model, { get(obj, prop) { if (prop in obj) return obj[prop] const lowerProp = prop.toLowerCase() const ownProp = Object.keys(model).find(k => k.toLowerCase() === lowerProp) const value = obj[ownProp] return value instanceof Object ? getModel(value) : value } }) } const wrapped = getModel(model) console.log(wrapped.corruptKey) console.log(wrapped.innerKey.x) console.log(wrapped.innerKey.y) console.log(wrapped.arr.map(x => x.FIRSt))