Skip to content

Latest commit

 

History

History
37 lines (24 loc) · 963 Bytes

File metadata and controls

37 lines (24 loc) · 963 Bytes
description Native alternatives to the extend package for deep cloning and merging objects

Replacements for extend

structuredClone (native)

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 ++]

Spread syntax

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 }

defu

If you need to deep merge two objects, you can use defu:

import { defu } from 'defu'

const options = defu(object, ...defaults)