Skip to content

Instantly share code, notes, and snippets.

@nmanumr
Last active July 7, 2024 19:27
Show Gist options
  • Save nmanumr/c26723a858429d782263c05b518699de to your computer and use it in GitHub Desktop.
Save nmanumr/c26723a858429d782263c05b518699de to your computer and use it in GitHub Desktop.
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