| description | Native alternatives to the extend package for deep cloning and merging objects |
|---|
If you only need to deep clone an object, you can use structuredClone:
import extend from 'extend' // [!code --]
extend(true, {}, config) // true [!code --]
structuredClone(config) // true [!code ++]If you need to merge two shallow objects, you can use spread syntax:
const obj1 = { foo: 'bar', x: 42 }
const obj2 = { bar: 'baz', y: 13 }
const mergedObj = { ...obj1, ...obj2 }If you need to deep merge two objects, you can use defu:
import { defu } from 'defu'
const options = defu(object, ...defaults)