bunshin-clone 1.0.8 → 1.0.10

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 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
  }
@@ -150,11 +149,17 @@ function cloneError(value, options, ref) {
150
149
  result.name = name;
151
150
  }
152
151
  ref.set(value, result);
152
+ if (value.stack) {
153
+ try {
154
+ result.stack = value.stack;
155
+ } catch {
156
+ }
157
+ }
153
158
  if ("cause" in value && value.cause !== void 0) {
154
159
  result.cause = clone(value.cause, options, ref);
155
160
  }
156
- if (value.stack) {
157
- result.stack = value.stack;
161
+ for (const key of Object.keys(value)) {
162
+ result[key] = clone(value[key], options, ref);
158
163
  }
159
164
  return result;
160
165
  }
@@ -162,14 +167,12 @@ function cloneWithDescriptors(node, options, ref) {
162
167
  const result = Object.create(Object.getPrototypeOf(node));
163
168
  ref.set(node, result);
164
169
  const descs = Object.getOwnPropertyDescriptors(node);
165
- const keys = Reflect.ownKeys(descs);
166
- for (let i = 0, l = keys.length; i < l; i++) {
167
- const key = keys[i];
170
+ forEachOwnKey(descs, (key) => {
168
171
  if (!key) {
169
- continue;
172
+ return;
170
173
  }
171
174
  if (isUnsafeKey(key)) {
172
- continue;
175
+ return;
173
176
  }
174
177
  const desc = { ...descs[key] };
175
178
  if ("value" in desc) {
@@ -182,14 +185,31 @@ function cloneWithDescriptors(node, options, ref) {
182
185
  throw error;
183
186
  }
184
187
  }
185
- }
188
+ });
186
189
  return result;
187
190
  }
191
+ function forEachOwnKey(object, callback) {
192
+ for (const key of Object.keys(object)) {
193
+ callback(key);
194
+ }
195
+ const symbols = Object.getOwnPropertySymbols(object);
196
+ for (let i = 0, l = symbols.length; i < l; i++) {
197
+ const symbol = symbols[i];
198
+ if (!symbol) {
199
+ continue;
200
+ }
201
+ callback(symbol);
202
+ }
203
+ }
188
204
  function isObject(value) {
189
205
  return typeof value === "object" && value !== null;
190
206
  }
191
207
  function isPlainObject(value) {
192
- return OBJECT_TO_STRING.call(value) === "[object Object]";
208
+ if (value === null || typeof value !== "object") {
209
+ return false;
210
+ }
211
+ const proto = Object.getPrototypeOf(value);
212
+ return proto === Object.prototype || proto === null;
193
213
  }
194
214
  function isUnsafeKey(key) {
195
215
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
@@ -199,7 +219,7 @@ function isUnsafeKey(key) {
199
219
  * High-performance deep clone utility with descriptor support.
200
220
  * Supports circular ref and complex built-in types.
201
221
  *
202
- * @version 1.0.8
222
+ * @version 1.0.10
203
223
  * @author Yusuke Kamiyamane
204
224
  * @license MIT
205
225
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * High-performance deep clone utility with descriptor support.
4
4
  * Supports circular ref and complex built-in types.
5
5
  *
6
- * @version 1.0.8
6
+ * @version 1.0.10
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * High-performance deep clone utility with descriptor support.
4
4
  * Supports circular ref and complex built-in types.
5
5
  *
6
- * @version 1.0.8
6
+ * @version 1.0.10
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
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
  }
@@ -148,11 +147,17 @@ function cloneError(value, options, ref) {
148
147
  result.name = name;
149
148
  }
150
149
  ref.set(value, result);
150
+ if (value.stack) {
151
+ try {
152
+ result.stack = value.stack;
153
+ } catch {
154
+ }
155
+ }
151
156
  if ("cause" in value && value.cause !== void 0) {
152
157
  result.cause = clone(value.cause, options, ref);
153
158
  }
154
- if (value.stack) {
155
- result.stack = value.stack;
159
+ for (const key of Object.keys(value)) {
160
+ result[key] = clone(value[key], options, ref);
156
161
  }
157
162
  return result;
158
163
  }
@@ -160,14 +165,12 @@ function cloneWithDescriptors(node, options, ref) {
160
165
  const result = Object.create(Object.getPrototypeOf(node));
161
166
  ref.set(node, result);
162
167
  const descs = Object.getOwnPropertyDescriptors(node);
163
- const keys = Reflect.ownKeys(descs);
164
- for (let i = 0, l = keys.length; i < l; i++) {
165
- const key = keys[i];
168
+ forEachOwnKey(descs, (key) => {
166
169
  if (!key) {
167
- continue;
170
+ return;
168
171
  }
169
172
  if (isUnsafeKey(key)) {
170
- continue;
173
+ return;
171
174
  }
172
175
  const desc = { ...descs[key] };
173
176
  if ("value" in desc) {
@@ -180,14 +183,31 @@ function cloneWithDescriptors(node, options, ref) {
180
183
  throw error;
181
184
  }
182
185
  }
183
- }
186
+ });
184
187
  return result;
185
188
  }
189
+ function forEachOwnKey(object, callback) {
190
+ for (const key of Object.keys(object)) {
191
+ callback(key);
192
+ }
193
+ const symbols = Object.getOwnPropertySymbols(object);
194
+ for (let i = 0, l = symbols.length; i < l; i++) {
195
+ const symbol = symbols[i];
196
+ if (!symbol) {
197
+ continue;
198
+ }
199
+ callback(symbol);
200
+ }
201
+ }
186
202
  function isObject(value) {
187
203
  return typeof value === "object" && value !== null;
188
204
  }
189
205
  function isPlainObject(value) {
190
- return OBJECT_TO_STRING.call(value) === "[object Object]";
206
+ if (value === null || typeof value !== "object") {
207
+ return false;
208
+ }
209
+ const proto = Object.getPrototypeOf(value);
210
+ return proto === Object.prototype || proto === null;
191
211
  }
192
212
  function isUnsafeKey(key) {
193
213
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
@@ -197,7 +217,7 @@ function isUnsafeKey(key) {
197
217
  * High-performance deep clone utility with descriptor support.
198
218
  * Supports circular ref and complex built-in types.
199
219
  *
200
- * @version 1.0.8
220
+ * @version 1.0.10
201
221
  * @author Yusuke Kamiyamane
202
222
  * @license MIT
203
223
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",