Skip to content

Replacements for extend

structuredClone (native)

If you only need to deep clone an object, you can use structuredClone:

ts
import extend from 'extend'

extend(true, {}, config) // true
structuredClone(config) // true

Spread syntax

If you need to merge two shallow objects, you can use spread syntax:

ts
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:

ts
import { defu } from 'defu'

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

Released under the MIT License. (1f304c6e)