Recursively assign default properties. Lightweight and Fast!
Install package:
npm install defu
OR
yarn add defu
const options = defu (object, defaults)
- object (Object): The destination object.
- source (Object): The source object.
const defu = require('defu')
console.log(defu({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }))
// => { a: { b: 2, c: 3 } }
-
object
anddefaults
are not modified -
Assignment of
__proto__
andconstructor
keys will be skipped to prevent security issues with object pollution.
MIT. Made with 💖