Created
March 10, 2020 00:45
-
-
Save alacret/f1cecb489c8831eda25152f807cd0590 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
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