bunshin-clone 1.0.8 → 1.0.9
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/dist/index.cjs +23 -9
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
var EMPTY_OPTIONS = {};
|
|
5
5
|
var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
6
|
-
var { toString: OBJECT_TO_STRING } = Object.prototype;
|
|
7
6
|
function bunshinClone(source, options) {
|
|
8
7
|
return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
|
|
9
8
|
}
|
|
@@ -162,14 +161,12 @@ function cloneWithDescriptors(node, options, ref) {
|
|
|
162
161
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
163
162
|
ref.set(node, result);
|
|
164
163
|
const descs = Object.getOwnPropertyDescriptors(node);
|
|
165
|
-
|
|
166
|
-
for (let i = 0, l = keys.length; i < l; i++) {
|
|
167
|
-
const key = keys[i];
|
|
164
|
+
forEachOwnKey(descs, (key) => {
|
|
168
165
|
if (!key) {
|
|
169
|
-
|
|
166
|
+
return;
|
|
170
167
|
}
|
|
171
168
|
if (isUnsafeKey(key)) {
|
|
172
|
-
|
|
169
|
+
return;
|
|
173
170
|
}
|
|
174
171
|
const desc = { ...descs[key] };
|
|
175
172
|
if ("value" in desc) {
|
|
@@ -182,14 +179,31 @@ function cloneWithDescriptors(node, options, ref) {
|
|
|
182
179
|
throw error;
|
|
183
180
|
}
|
|
184
181
|
}
|
|
185
|
-
}
|
|
182
|
+
});
|
|
186
183
|
return result;
|
|
187
184
|
}
|
|
185
|
+
function forEachOwnKey(object, callback) {
|
|
186
|
+
for (const key of Object.keys(object)) {
|
|
187
|
+
callback(key);
|
|
188
|
+
}
|
|
189
|
+
const symbols = Object.getOwnPropertySymbols(object);
|
|
190
|
+
for (let i = 0, l = symbols.length; i < l; i++) {
|
|
191
|
+
const symbol = symbols[i];
|
|
192
|
+
if (!symbol) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
callback(symbol);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
188
198
|
function isObject(value) {
|
|
189
199
|
return typeof value === "object" && value !== null;
|
|
190
200
|
}
|
|
191
201
|
function isPlainObject(value) {
|
|
192
|
-
|
|
202
|
+
if (value === null || typeof value !== "object") {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const proto = Object.getPrototypeOf(value);
|
|
206
|
+
return proto === Object.prototype || proto === null;
|
|
193
207
|
}
|
|
194
208
|
function isUnsafeKey(key) {
|
|
195
209
|
return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
|
|
@@ -199,7 +213,7 @@ function isUnsafeKey(key) {
|
|
|
199
213
|
* High-performance deep clone utility with descriptor support.
|
|
200
214
|
* Supports circular ref and complex built-in types.
|
|
201
215
|
*
|
|
202
|
-
* @version 1.0.
|
|
216
|
+
* @version 1.0.9
|
|
203
217
|
* @author Yusuke Kamiyamane
|
|
204
218
|
* @license MIT
|
|
205
219
|
* @copyright Copyright (c) 2026 Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
var EMPTY_OPTIONS = {};
|
|
3
3
|
var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
4
|
-
var { toString: OBJECT_TO_STRING } = Object.prototype;
|
|
5
4
|
function bunshinClone(source, options) {
|
|
6
5
|
return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
|
|
7
6
|
}
|
|
@@ -160,14 +159,12 @@ function cloneWithDescriptors(node, options, ref) {
|
|
|
160
159
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
161
160
|
ref.set(node, result);
|
|
162
161
|
const descs = Object.getOwnPropertyDescriptors(node);
|
|
163
|
-
|
|
164
|
-
for (let i = 0, l = keys.length; i < l; i++) {
|
|
165
|
-
const key = keys[i];
|
|
162
|
+
forEachOwnKey(descs, (key) => {
|
|
166
163
|
if (!key) {
|
|
167
|
-
|
|
164
|
+
return;
|
|
168
165
|
}
|
|
169
166
|
if (isUnsafeKey(key)) {
|
|
170
|
-
|
|
167
|
+
return;
|
|
171
168
|
}
|
|
172
169
|
const desc = { ...descs[key] };
|
|
173
170
|
if ("value" in desc) {
|
|
@@ -180,14 +177,31 @@ function cloneWithDescriptors(node, options, ref) {
|
|
|
180
177
|
throw error;
|
|
181
178
|
}
|
|
182
179
|
}
|
|
183
|
-
}
|
|
180
|
+
});
|
|
184
181
|
return result;
|
|
185
182
|
}
|
|
183
|
+
function forEachOwnKey(object, callback) {
|
|
184
|
+
for (const key of Object.keys(object)) {
|
|
185
|
+
callback(key);
|
|
186
|
+
}
|
|
187
|
+
const symbols = Object.getOwnPropertySymbols(object);
|
|
188
|
+
for (let i = 0, l = symbols.length; i < l; i++) {
|
|
189
|
+
const symbol = symbols[i];
|
|
190
|
+
if (!symbol) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
callback(symbol);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
186
196
|
function isObject(value) {
|
|
187
197
|
return typeof value === "object" && value !== null;
|
|
188
198
|
}
|
|
189
199
|
function isPlainObject(value) {
|
|
190
|
-
|
|
200
|
+
if (value === null || typeof value !== "object") {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
const proto = Object.getPrototypeOf(value);
|
|
204
|
+
return proto === Object.prototype || proto === null;
|
|
191
205
|
}
|
|
192
206
|
function isUnsafeKey(key) {
|
|
193
207
|
return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
|
|
@@ -197,7 +211,7 @@ function isUnsafeKey(key) {
|
|
|
197
211
|
* High-performance deep clone utility with descriptor support.
|
|
198
212
|
* Supports circular ref and complex built-in types.
|
|
199
213
|
*
|
|
200
|
-
* @version 1.0.
|
|
214
|
+
* @version 1.0.9
|
|
201
215
|
* @author Yusuke Kamiyamane
|
|
202
216
|
* @license MIT
|
|
203
217
|
* @copyright Copyright (c) 2026 Yusuke Kamiyamane
|