Last active
July 7, 2024 19:27
-
-
Save nmanumr/c26723a858429d782263c05b518699de to your computer and use it in GitHub Desktop.
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 characters
const fakeObjectSymbol = Symbol('fakeObject'); | |
function getFakeNestedObject(baseName) { | |
return new Proxy( | |
{ | |
toString() => baseName, | |
deps: baseName, | |
[fakeObjectSymbol]: true, | |
}, | |
{ | |
get(target, prop, receiver) { | |
if (['toString', 'deps', fakeObjectSymbol].includes(prop)) { | |
return Reflect.get(target, prop, receiver); | |
} | |
return getFakeNestedObject( | |
[baseName, prop.toString()].filter((e) => ![undefined, null, ''].includes(e)).join('.') | |
); | |
}, | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment