bunshin-clone 1.2.9 → 1.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.cjs +20 -20
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ npm i bunshin-clone
|
|
|
13
13
|
import { bunshinClone } from 'bunshin-clone';
|
|
14
14
|
|
|
15
15
|
// CDNs
|
|
16
|
-
import { bunshinClone } from 'https://esm.sh/bunshin-clone@1.2.
|
|
16
|
+
import { bunshinClone } from 'https://esm.sh/bunshin-clone@1.2.11';
|
|
17
17
|
// or
|
|
18
|
-
import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.
|
|
18
|
+
import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.11/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.2.
|
|
20
|
+
import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.2.11';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.cjs
CHANGED
|
@@ -28,27 +28,27 @@ function clone(node, options, refs) {
|
|
|
28
28
|
if (isPlainObject(node)) {
|
|
29
29
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
30
30
|
refs.set(node, result);
|
|
31
|
-
for (const
|
|
32
|
-
if (!HAS_OWN.call(node,
|
|
31
|
+
for (const key in node) {
|
|
32
|
+
if (!HAS_OWN.call(node, key) || isUnsafeKey(key)) {
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
|
-
result[
|
|
35
|
+
result[key] = clone(node[key], options, refs);
|
|
36
36
|
}
|
|
37
37
|
return result;
|
|
38
38
|
}
|
|
39
39
|
if (node instanceof Map) {
|
|
40
40
|
const result = /* @__PURE__ */ new Map();
|
|
41
41
|
refs.set(node, result);
|
|
42
|
-
for (const [
|
|
43
|
-
result.set(clone(
|
|
42
|
+
for (const [key, value] of node) {
|
|
43
|
+
result.set(clone(key, options, refs), clone(value, options, refs));
|
|
44
44
|
}
|
|
45
45
|
return result;
|
|
46
46
|
}
|
|
47
47
|
if (node instanceof Set) {
|
|
48
48
|
const result = /* @__PURE__ */ new Set();
|
|
49
49
|
refs.set(node, result);
|
|
50
|
-
for (const
|
|
51
|
-
result.add(clone(
|
|
50
|
+
for (const item of node) {
|
|
51
|
+
result.add(clone(item, options, refs));
|
|
52
52
|
}
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
@@ -104,8 +104,8 @@ function clone(node, options, refs) {
|
|
|
104
104
|
if (node instanceof URLSearchParams) {
|
|
105
105
|
const result = new URLSearchParams();
|
|
106
106
|
refs.set(node, result);
|
|
107
|
-
for (const [
|
|
108
|
-
result.append(
|
|
107
|
+
for (const [key, value] of node) {
|
|
108
|
+
result.append(key, value);
|
|
109
109
|
}
|
|
110
110
|
return result;
|
|
111
111
|
}
|
|
@@ -153,8 +153,8 @@ function cloneError(value, options, refs) {
|
|
|
153
153
|
if ("cause" in value && cause !== void 0) {
|
|
154
154
|
result.cause = clone(cause, options, refs);
|
|
155
155
|
}
|
|
156
|
-
for (const
|
|
157
|
-
result[
|
|
156
|
+
for (const key of Object.keys(value)) {
|
|
157
|
+
result[key] = clone(value[key], options, refs);
|
|
158
158
|
}
|
|
159
159
|
return result;
|
|
160
160
|
}
|
|
@@ -162,16 +162,16 @@ function cloneWithDescriptors(node, options, refs) {
|
|
|
162
162
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
163
163
|
refs.set(node, result);
|
|
164
164
|
const descs = Object.getOwnPropertyDescriptors(node);
|
|
165
|
-
forEachOwnKey(descs, (
|
|
166
|
-
if (isUnsafeKey(
|
|
165
|
+
forEachOwnKey(descs, (key) => {
|
|
166
|
+
if (isUnsafeKey(key)) {
|
|
167
167
|
return;
|
|
168
168
|
}
|
|
169
|
-
const desc = { ...descs[
|
|
169
|
+
const desc = { ...descs[key] };
|
|
170
170
|
if ("value" in desc) {
|
|
171
171
|
desc.value = clone(desc.value, options, refs);
|
|
172
172
|
}
|
|
173
173
|
try {
|
|
174
|
-
Object.defineProperty(result,
|
|
174
|
+
Object.defineProperty(result, key, desc);
|
|
175
175
|
} catch (error) {
|
|
176
176
|
if (options.strictDescriptors) {
|
|
177
177
|
throw error;
|
|
@@ -181,11 +181,11 @@ function cloneWithDescriptors(node, options, refs) {
|
|
|
181
181
|
return result;
|
|
182
182
|
}
|
|
183
183
|
function forEachOwnKey(object, fn) {
|
|
184
|
-
for (const
|
|
185
|
-
fn(
|
|
184
|
+
for (const key of Object.keys(object)) {
|
|
185
|
+
fn(key);
|
|
186
186
|
}
|
|
187
|
-
for (const
|
|
188
|
-
fn(
|
|
187
|
+
for (const symbol of Object.getOwnPropertySymbols(object)) {
|
|
188
|
+
fn(symbol);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
function isObject(value) {
|
|
@@ -206,7 +206,7 @@ function isUnsafeKey(key) {
|
|
|
206
206
|
* High-performance deep clone utility with descriptor support.
|
|
207
207
|
* Handles circular ref and complex built-in types.
|
|
208
208
|
*
|
|
209
|
-
* @version 1.2.
|
|
209
|
+
* @version 1.2.11
|
|
210
210
|
* @author Yusuke Kamiyamane
|
|
211
211
|
* @license MIT
|
|
212
212
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -26,27 +26,27 @@ function clone(node, options, refs) {
|
|
|
26
26
|
if (isPlainObject(node)) {
|
|
27
27
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
28
28
|
refs.set(node, result);
|
|
29
|
-
for (const
|
|
30
|
-
if (!HAS_OWN.call(node,
|
|
29
|
+
for (const key in node) {
|
|
30
|
+
if (!HAS_OWN.call(node, key) || isUnsafeKey(key)) {
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
|
-
result[
|
|
33
|
+
result[key] = clone(node[key], options, refs);
|
|
34
34
|
}
|
|
35
35
|
return result;
|
|
36
36
|
}
|
|
37
37
|
if (node instanceof Map) {
|
|
38
38
|
const result = /* @__PURE__ */ new Map();
|
|
39
39
|
refs.set(node, result);
|
|
40
|
-
for (const [
|
|
41
|
-
result.set(clone(
|
|
40
|
+
for (const [key, value] of node) {
|
|
41
|
+
result.set(clone(key, options, refs), clone(value, options, refs));
|
|
42
42
|
}
|
|
43
43
|
return result;
|
|
44
44
|
}
|
|
45
45
|
if (node instanceof Set) {
|
|
46
46
|
const result = /* @__PURE__ */ new Set();
|
|
47
47
|
refs.set(node, result);
|
|
48
|
-
for (const
|
|
49
|
-
result.add(clone(
|
|
48
|
+
for (const item of node) {
|
|
49
|
+
result.add(clone(item, options, refs));
|
|
50
50
|
}
|
|
51
51
|
return result;
|
|
52
52
|
}
|
|
@@ -102,8 +102,8 @@ function clone(node, options, refs) {
|
|
|
102
102
|
if (node instanceof URLSearchParams) {
|
|
103
103
|
const result = new URLSearchParams();
|
|
104
104
|
refs.set(node, result);
|
|
105
|
-
for (const [
|
|
106
|
-
result.append(
|
|
105
|
+
for (const [key, value] of node) {
|
|
106
|
+
result.append(key, value);
|
|
107
107
|
}
|
|
108
108
|
return result;
|
|
109
109
|
}
|
|
@@ -151,8 +151,8 @@ function cloneError(value, options, refs) {
|
|
|
151
151
|
if ("cause" in value && cause !== void 0) {
|
|
152
152
|
result.cause = clone(cause, options, refs);
|
|
153
153
|
}
|
|
154
|
-
for (const
|
|
155
|
-
result[
|
|
154
|
+
for (const key of Object.keys(value)) {
|
|
155
|
+
result[key] = clone(value[key], options, refs);
|
|
156
156
|
}
|
|
157
157
|
return result;
|
|
158
158
|
}
|
|
@@ -160,16 +160,16 @@ function cloneWithDescriptors(node, options, refs) {
|
|
|
160
160
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
161
161
|
refs.set(node, result);
|
|
162
162
|
const descs = Object.getOwnPropertyDescriptors(node);
|
|
163
|
-
forEachOwnKey(descs, (
|
|
164
|
-
if (isUnsafeKey(
|
|
163
|
+
forEachOwnKey(descs, (key) => {
|
|
164
|
+
if (isUnsafeKey(key)) {
|
|
165
165
|
return;
|
|
166
166
|
}
|
|
167
|
-
const desc = { ...descs[
|
|
167
|
+
const desc = { ...descs[key] };
|
|
168
168
|
if ("value" in desc) {
|
|
169
169
|
desc.value = clone(desc.value, options, refs);
|
|
170
170
|
}
|
|
171
171
|
try {
|
|
172
|
-
Object.defineProperty(result,
|
|
172
|
+
Object.defineProperty(result, key, desc);
|
|
173
173
|
} catch (error) {
|
|
174
174
|
if (options.strictDescriptors) {
|
|
175
175
|
throw error;
|
|
@@ -179,11 +179,11 @@ function cloneWithDescriptors(node, options, refs) {
|
|
|
179
179
|
return result;
|
|
180
180
|
}
|
|
181
181
|
function forEachOwnKey(object, fn) {
|
|
182
|
-
for (const
|
|
183
|
-
fn(
|
|
182
|
+
for (const key of Object.keys(object)) {
|
|
183
|
+
fn(key);
|
|
184
184
|
}
|
|
185
|
-
for (const
|
|
186
|
-
fn(
|
|
185
|
+
for (const symbol of Object.getOwnPropertySymbols(object)) {
|
|
186
|
+
fn(symbol);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
function isObject(value) {
|
|
@@ -204,7 +204,7 @@ function isUnsafeKey(key) {
|
|
|
204
204
|
* High-performance deep clone utility with descriptor support.
|
|
205
205
|
* Handles circular ref and complex built-in types.
|
|
206
206
|
*
|
|
207
|
-
* @version 1.2.
|
|
207
|
+
* @version 1.2.11
|
|
208
208
|
* @author Yusuke Kamiyamane
|
|
209
209
|
* @license MIT
|
|
210
210
|
* @copyright Copyright (c) Yusuke Kamiyamane
|