Created
September 9, 2019 19:49
-
-
Save reeddunkle/017914be42658568b857c2ddc0f0c594 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
| /* | |
| TODO: Change API to make `paths` an array of strings | object | |
| */ | |
| const pickAs = (obj, paths) => { | |
| return Object.entries(paths).reduce((accumulator, [path, definition]) => { | |
| const resultValue = get(obj, path); | |
| if (definition === true) { | |
| accumulator[path] = resultValue; | |
| } else if (isFunction(definition)) { | |
| accumulator[definition(resultValue, path, obj)] = resultValue; | |
| } else { | |
| accumulator[definition] = resultValue; | |
| } | |
| return accumulator; | |
| }, {}); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment