Skip to content

Instantly share code, notes, and snippets.

@alacret
Created March 10, 2020 00:45
Show Gist options
  • Save alacret/f1cecb489c8831eda25152f807cd0590 to your computer and use it in GitHub Desktop.
Save alacret/f1cecb489c8831eda25152f807cd0590 to your computer and use it in GitHub Desktop.
function partialKeys (obj) {
const keys = Object.keys(obj);
keys.sort();
const handler = {
get(obj, name) {
for(let i = 0, j= keys.length; i<j;i++){
if(keys[i].startsWith(name))
return obj[keys[i]];
}
},
};
const api = new Proxy(obj, handler);
return api;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment