From 6f185d71a86a6fe04e09a34685bcc5e6d84d5085 Mon Sep 17 00:00:00 2001 From: Francesco Menghi <53121061+menghif@users.noreply.github.com> Date: Sat, 7 Oct 2023 21:03:55 -0400 Subject: [PATCH] add _.cloneDeep --- README.md | 28 ++++++++++++++++++++++++++++ lib/rules/rules.json | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/README.md b/README.md index d14ff8e..2bd1095 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. diff --git a/lib/rules/rules.json b/lib/rules/rules.json index 9620f4c..28a06a7 100644 --- a/lib/rules/rules.json +++ b/lib/rules/rules.json @@ -289,6 +289,10 @@ "compatible": true, "alternative": "Array.isArray(arr) ? arr : [arr]" }, + "cloneDeep": { + "compatible": true, + "alternative": "structuredClone()" + }, "isFunction": { "compatible": true, "alternative": "typeof func === \"function\""