Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ESLint plugin.
- [`event-stream`](./event-stream.md)
- [`execa`](./execa.md)
- [`express`](./express.md)
- [`extend`](./extend.md)
- [`ezspawn`](./ez-spawn.md)
- [`faker`](./faker.md)
- [`fast-glob`](./fast-glob.md)
Expand Down
37 changes: 37 additions & 0 deletions docs/modules/extend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
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`](https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone):

```ts
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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#spread_in_object_literals):

```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`](https://github.com/unjs/defu):

```ts
import { defu } from 'defu'

const options = defu(object, ...defaults)
```
21 changes: 21 additions & 0 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@
"replacements": ["h3", "tinyhttp", "hono", "elysia"],
"url": {"type": "e18e", "id": "express"}
},
"extend": {
"type": "module",
"moduleName": "extend",
"replacements": ["structuredClone", "defu"],
"url": {"type": "e18e", "id": "extend"}
},
"ez-spawn": {
"type": "module",
"moduleName": "ez-spawn",
Expand Down Expand Up @@ -2958,6 +2964,12 @@
"url": {"type": "e18e", "id": "moment"},
"replacementModule": "day.js"
},
"defu": {
"id": "defu",
"type": "documented",
"url": {"type": "e18e", "id": "extend"},
"replacementModule": "defu"
},
"dequal": {
"id": "dequal",
"type": "documented",
Expand Down Expand Up @@ -3417,6 +3429,15 @@
},
"url": {"type": "mdn", "id": "Web/API/Streams_API"}
},
"structuredClone": {
"id": "structuredClone",
"type": "native",
"webFeatureId": {
"featureId": "structured-clone",
"compatKey": "api.structuredClone"
},
"url": {"type": "mdn", "id": "Web/API/Window/structuredClone"}
},
"tiny-invariant": {
"id": "tiny-invariant",
"type": "documented",
Expand Down