Created
May 18, 2020 13:25
-
-
Save tomgidden/ba8519640f38ce900b709f12773dd920 to your computer and use it in GitHub Desktop.
subset an object with defaults
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 subset = (props, defaults) => Object.fromEntries((function *() { | |
for (const k in defaults) { | |
if (undefined !== defaults[k]) { | |
if (undefined !== props[k]) | |
yield [k, props[k]]; | |
else | |
yield [k, defaults[k]]; | |
} | |
} | |
}())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment