Skip to content

Commit

Permalink
Merge pull request #382 from menghif/issue-349
Browse files Browse the repository at this point in the history
Add _.cloneDeep
  • Loading branch information
stevemao authored Oct 9, 2023
2 parents 49c0168 + 6f185d7 commit d8d098d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ For more information, see [Configuring the ESLint Plugin](configuring.md)
**[Lang](#lang)**

1. [_.castArray](#_castarray)
1. [.cloneDeep](#_clonedeep)
1. [_.gt](#_gt)
1. [_.gte](#_gte)
1. [_.isDate](#_isdate)
Expand Down Expand Up @@ -2075,6 +2076,33 @@ console.log(castArray([2]));

**[⬆ back to top](#quick-links)**

### _.cloneDeep
Creates a deep copy by recursively cloning the value.

```js
// Lodash
var objects = [{ 'a': 1 }, { 'b': 2 }];

var clone = _.cloneDeep(objects);
console.log(clone[0] === objects[0]);
// output: false

// Native
var objects = [{ 'a': 1 }, { 'b': 2 }];

var clone = structuredClone(objects);
console.log(clone[0] === objects[0]);
// output: false
```

#### Browser Support for `structuredClone()`

![Chrome][chrome-image] | ![Edge][edge-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image]
:-: | :-: | :-: | :-: | :-: | :-: |
98.0 ✔ | 98.0 ✔ | 94.0 ✔ | ✖ | 84.0 ✔ | 15.4 ✔ |

**[⬆ back to top](#quick-links)**

### _.isDate

Checks if value is classified as a Date object.
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
"compatible": true,
"alternative": "Array.isArray(arr) ? arr : [arr]"
},
"cloneDeep": {
"compatible": true,
"alternative": "structuredClone()"
},
"isFunction": {
"compatible": true,
"alternative": "typeof func === \"function\""
Expand Down

0 comments on commit d8d098d

Please sign in to comment.