Skip to content

Instantly share code, notes, and snippets.

@tomgidden
Created May 18, 2020 13:25
Show Gist options
  • Save tomgidden/ba8519640f38ce900b709f12773dd920 to your computer and use it in GitHub Desktop.
Save tomgidden/ba8519640f38ce900b709f12773dd920 to your computer and use it in GitHub Desktop.
subset an object with defaults
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