Skip to content

Commit d8d098d

Browse files
authored
Merge pull request you-dont-need#382 from menghif/issue-349
Add _.cloneDeep
2 parents 49c0168 + 6f185d7 commit d8d098d

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ For more information, see [Configuring the ESLint Plugin](configuring.md)
143143
**[Lang](#lang)**
144144

145145
1. [_.castArray](#_castarray)
146+
1. [.cloneDeep](#_clonedeep)
146147
1. [_.gt](#_gt)
147148
1. [_.gte](#_gte)
148149
1. [_.isDate](#_isdate)
@@ -2075,6 +2076,33 @@ console.log(castArray([2]));
20752076

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

2079+
### _.cloneDeep
2080+
Creates a deep copy by recursively cloning the value.
2081+
2082+
```js
2083+
// Lodash
2084+
var objects = [{ 'a': 1 }, { 'b': 2 }];
2085+
2086+
var clone = _.cloneDeep(objects);
2087+
console.log(clone[0] === objects[0]);
2088+
// output: false
2089+
2090+
// Native
2091+
var objects = [{ 'a': 1 }, { 'b': 2 }];
2092+
2093+
var clone = structuredClone(objects);
2094+
console.log(clone[0] === objects[0]);
2095+
// output: false
2096+
```
2097+
2098+
#### Browser Support for `structuredClone()`
2099+
2100+
![Chrome][chrome-image] | ![Edge][edge-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image]
2101+
:-: | :-: | :-: | :-: | :-: | :-: |
2102+
98.0 ✔ | 98.0 ✔ | 94.0 ✔ | ✖ | 84.0 ✔ | 15.4 ✔ |
2103+
2104+
**[⬆ back to top](#quick-links)**
2105+
20782106
### _.isDate
20792107

20802108
Checks if value is classified as a Date object.

lib/rules/rules.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@
289289
"compatible": true,
290290
"alternative": "Array.isArray(arr) ? arr : [arr]"
291291
},
292+
"cloneDeep": {
293+
"compatible": true,
294+
"alternative": "structuredClone()"
295+
},
292296
"isFunction": {
293297
"compatible": true,
294298
"alternative": "typeof func === \"function\""

0 commit comments

Comments
 (0)