bunshin-clone 1.2.7 → 1.2.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Yusuke Kamiyamane
3
+ Copyright (c) Yusuke Kamiyamane
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.7';
16
+ import { bunshinClone } from 'https://esm.sh/bunshin-clone@1.2.9';
17
17
  // or
18
- import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.7/+esm';
18
+ import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.9/+esm';
19
19
  // or
20
- import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.2.7';
20
+ import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.2.9';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -104,7 +104,7 @@ result.self === result; // true
104
104
  const source = {
105
105
  get x() {
106
106
  return 42;
107
- }
107
+ },
108
108
  };
109
109
 
110
110
  const result = bunshinClone(source);
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 key in node) {
32
- if (!HAS_OWN.call(node, key) || isUnsafeKey(key)) {
31
+ for (const k in node) {
32
+ if (!HAS_OWN.call(node, k) || isUnsafeKey(k)) {
33
33
  continue;
34
34
  }
35
- result[key] = clone(node[key], options, refs);
35
+ result[k] = clone(node[k], 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 [key, value] of node) {
43
- result.set(clone(key, options, refs), clone(value, options, refs));
42
+ for (const [k, v] of node) {
43
+ result.set(clone(k, options, refs), clone(v, 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 item of node) {
51
- result.add(clone(item, options, refs));
50
+ for (const i of node) {
51
+ result.add(clone(i, options, refs));
52
52
  }
53
53
  return result;
54
54
  }
@@ -80,33 +80,32 @@ function clone(node, options, refs) {
80
80
  refs.set(node, result);
81
81
  return result;
82
82
  }
83
- if (node instanceof Error || typeof DOMException !== "undefined" && node instanceof DOMException) {
83
+ if (node instanceof Error || node instanceof DOMException) {
84
84
  return cloneError(node, options, refs);
85
85
  }
86
- if (typeof Blob !== "undefined" && node instanceof Blob) {
86
+ if (node instanceof Blob) {
87
87
  const result = node.slice(0, node.size, node.type);
88
88
  refs.set(node, result);
89
89
  return result;
90
90
  }
91
91
  if (typeof ImageData !== "undefined" && node instanceof ImageData) {
92
- const result = new ImageData(
93
- new Uint8ClampedArray(node.data),
94
- node.width,
95
- node.height
96
- );
92
+ const { data, width, height, colorSpace } = node;
93
+ const result = new ImageData(new Uint8ClampedArray(data), width, height, {
94
+ colorSpace
95
+ });
97
96
  refs.set(node, result);
98
97
  return result;
99
98
  }
100
- if (typeof URL !== "undefined" && node instanceof URL) {
99
+ if (node instanceof URL) {
101
100
  const result = new URL(node.href);
102
101
  refs.set(node, result);
103
102
  return result;
104
103
  }
105
- if (typeof URLSearchParams !== "undefined" && node instanceof URLSearchParams) {
104
+ if (node instanceof URLSearchParams) {
106
105
  const result = new URLSearchParams();
107
106
  refs.set(node, result);
108
- for (const [key, value] of node) {
109
- result.append(key, value);
107
+ for (const [k, v] of node) {
108
+ result.append(k, v);
110
109
  }
111
110
  return result;
112
111
  }
@@ -114,13 +113,12 @@ function clone(node, options, refs) {
114
113
  return node;
115
114
  }
116
115
  function cloneError(value, options, refs) {
116
+ const { name, message, cause, stack } = value;
117
117
  if (value instanceof DOMException) {
118
- const result2 = new DOMException(value.message, value.name);
118
+ const result2 = new DOMException(message, name);
119
119
  refs.set(value, result2);
120
120
  return result2;
121
121
  }
122
- const name = value.name || "Error";
123
- const message = value.message || "";
124
122
  let result;
125
123
  switch (name) {
126
124
  case "EvalError":
@@ -146,17 +144,17 @@ function cloneError(value, options, refs) {
146
144
  result.name = name;
147
145
  }
148
146
  refs.set(value, result);
149
- if (value.stack) {
147
+ if (stack) {
150
148
  try {
151
- result.stack = value.stack;
149
+ result.stack = stack;
152
150
  } catch {
153
151
  }
154
152
  }
155
- if ("cause" in value && value.cause !== void 0) {
156
- result.cause = clone(value.cause, options, refs);
153
+ if ("cause" in value && cause !== void 0) {
154
+ result.cause = clone(cause, options, refs);
157
155
  }
158
- for (const key of Object.keys(value)) {
159
- result[key] = clone(value[key], options, refs);
156
+ for (const k of Object.keys(value)) {
157
+ result[k] = clone(value[k], options, refs);
160
158
  }
161
159
  return result;
162
160
  }
@@ -164,16 +162,16 @@ function cloneWithDescriptors(node, options, refs) {
164
162
  const result = Object.create(Object.getPrototypeOf(node));
165
163
  refs.set(node, result);
166
164
  const descs = Object.getOwnPropertyDescriptors(node);
167
- forEachOwnKey(descs, (key) => {
168
- if (isUnsafeKey(key)) {
165
+ forEachOwnKey(descs, (k) => {
166
+ if (isUnsafeKey(k)) {
169
167
  return;
170
168
  }
171
- const desc = { ...descs[key] };
169
+ const desc = { ...descs[k] };
172
170
  if ("value" in desc) {
173
171
  desc.value = clone(desc.value, options, refs);
174
172
  }
175
173
  try {
176
- Object.defineProperty(result, key, desc);
174
+ Object.defineProperty(result, k, desc);
177
175
  } catch (error) {
178
176
  if (options.strictDescriptors) {
179
177
  throw error;
@@ -183,12 +181,11 @@ function cloneWithDescriptors(node, options, refs) {
183
181
  return result;
184
182
  }
185
183
  function forEachOwnKey(object, fn) {
186
- for (const key of Object.keys(object)) {
187
- fn(key);
184
+ for (const k of Object.keys(object)) {
185
+ fn(k);
188
186
  }
189
- const symbols = Object.getOwnPropertySymbols(object);
190
- for (let i = 0, l = symbols.length; i < l; i++) {
191
- fn(symbols[i]);
187
+ for (const s of Object.getOwnPropertySymbols(object)) {
188
+ fn(s);
192
189
  }
193
190
  }
194
191
  function isObject(value) {
@@ -209,7 +206,7 @@ function isUnsafeKey(key) {
209
206
  * High-performance deep clone utility with descriptor support.
210
207
  * Handles circular ref and complex built-in types.
211
208
  *
212
- * @version 1.2.7
209
+ * @version 1.2.9
213
210
  * @author Yusuke Kamiyamane
214
211
  * @license MIT
215
212
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * High-performance deep clone utility with descriptor support.
4
4
  * Handles circular ref and complex built-in types.
5
5
  *
6
- * @version 1.2.7
6
+ * @version 1.2.9
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * High-performance deep clone utility with descriptor support.
4
4
  * Handles circular ref and complex built-in types.
5
5
  *
6
- * @version 1.2.7
6
+ * @version 1.2.9
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
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 key in node) {
30
- if (!HAS_OWN.call(node, key) || isUnsafeKey(key)) {
29
+ for (const k in node) {
30
+ if (!HAS_OWN.call(node, k) || isUnsafeKey(k)) {
31
31
  continue;
32
32
  }
33
- result[key] = clone(node[key], options, refs);
33
+ result[k] = clone(node[k], 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 [key, value] of node) {
41
- result.set(clone(key, options, refs), clone(value, options, refs));
40
+ for (const [k, v] of node) {
41
+ result.set(clone(k, options, refs), clone(v, 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 item of node) {
49
- result.add(clone(item, options, refs));
48
+ for (const i of node) {
49
+ result.add(clone(i, options, refs));
50
50
  }
51
51
  return result;
52
52
  }
@@ -78,33 +78,32 @@ function clone(node, options, refs) {
78
78
  refs.set(node, result);
79
79
  return result;
80
80
  }
81
- if (node instanceof Error || typeof DOMException !== "undefined" && node instanceof DOMException) {
81
+ if (node instanceof Error || node instanceof DOMException) {
82
82
  return cloneError(node, options, refs);
83
83
  }
84
- if (typeof Blob !== "undefined" && node instanceof Blob) {
84
+ if (node instanceof Blob) {
85
85
  const result = node.slice(0, node.size, node.type);
86
86
  refs.set(node, result);
87
87
  return result;
88
88
  }
89
89
  if (typeof ImageData !== "undefined" && node instanceof ImageData) {
90
- const result = new ImageData(
91
- new Uint8ClampedArray(node.data),
92
- node.width,
93
- node.height
94
- );
90
+ const { data, width, height, colorSpace } = node;
91
+ const result = new ImageData(new Uint8ClampedArray(data), width, height, {
92
+ colorSpace
93
+ });
95
94
  refs.set(node, result);
96
95
  return result;
97
96
  }
98
- if (typeof URL !== "undefined" && node instanceof URL) {
97
+ if (node instanceof URL) {
99
98
  const result = new URL(node.href);
100
99
  refs.set(node, result);
101
100
  return result;
102
101
  }
103
- if (typeof URLSearchParams !== "undefined" && node instanceof URLSearchParams) {
102
+ if (node instanceof URLSearchParams) {
104
103
  const result = new URLSearchParams();
105
104
  refs.set(node, result);
106
- for (const [key, value] of node) {
107
- result.append(key, value);
105
+ for (const [k, v] of node) {
106
+ result.append(k, v);
108
107
  }
109
108
  return result;
110
109
  }
@@ -112,13 +111,12 @@ function clone(node, options, refs) {
112
111
  return node;
113
112
  }
114
113
  function cloneError(value, options, refs) {
114
+ const { name, message, cause, stack } = value;
115
115
  if (value instanceof DOMException) {
116
- const result2 = new DOMException(value.message, value.name);
116
+ const result2 = new DOMException(message, name);
117
117
  refs.set(value, result2);
118
118
  return result2;
119
119
  }
120
- const name = value.name || "Error";
121
- const message = value.message || "";
122
120
  let result;
123
121
  switch (name) {
124
122
  case "EvalError":
@@ -144,17 +142,17 @@ function cloneError(value, options, refs) {
144
142
  result.name = name;
145
143
  }
146
144
  refs.set(value, result);
147
- if (value.stack) {
145
+ if (stack) {
148
146
  try {
149
- result.stack = value.stack;
147
+ result.stack = stack;
150
148
  } catch {
151
149
  }
152
150
  }
153
- if ("cause" in value && value.cause !== void 0) {
154
- result.cause = clone(value.cause, options, refs);
151
+ if ("cause" in value && cause !== void 0) {
152
+ result.cause = clone(cause, options, refs);
155
153
  }
156
- for (const key of Object.keys(value)) {
157
- result[key] = clone(value[key], options, refs);
154
+ for (const k of Object.keys(value)) {
155
+ result[k] = clone(value[k], options, refs);
158
156
  }
159
157
  return result;
160
158
  }
@@ -162,16 +160,16 @@ function cloneWithDescriptors(node, options, refs) {
162
160
  const result = Object.create(Object.getPrototypeOf(node));
163
161
  refs.set(node, result);
164
162
  const descs = Object.getOwnPropertyDescriptors(node);
165
- forEachOwnKey(descs, (key) => {
166
- if (isUnsafeKey(key)) {
163
+ forEachOwnKey(descs, (k) => {
164
+ if (isUnsafeKey(k)) {
167
165
  return;
168
166
  }
169
- const desc = { ...descs[key] };
167
+ const desc = { ...descs[k] };
170
168
  if ("value" in desc) {
171
169
  desc.value = clone(desc.value, options, refs);
172
170
  }
173
171
  try {
174
- Object.defineProperty(result, key, desc);
172
+ Object.defineProperty(result, k, desc);
175
173
  } catch (error) {
176
174
  if (options.strictDescriptors) {
177
175
  throw error;
@@ -181,12 +179,11 @@ function cloneWithDescriptors(node, options, refs) {
181
179
  return result;
182
180
  }
183
181
  function forEachOwnKey(object, fn) {
184
- for (const key of Object.keys(object)) {
185
- fn(key);
182
+ for (const k of Object.keys(object)) {
183
+ fn(k);
186
184
  }
187
- const symbols = Object.getOwnPropertySymbols(object);
188
- for (let i = 0, l = symbols.length; i < l; i++) {
189
- fn(symbols[i]);
185
+ for (const s of Object.getOwnPropertySymbols(object)) {
186
+ fn(s);
190
187
  }
191
188
  }
192
189
  function isObject(value) {
@@ -207,7 +204,7 @@ function isUnsafeKey(key) {
207
204
  * High-performance deep clone utility with descriptor support.
208
205
  * Handles circular ref and complex built-in types.
209
206
  *
210
- * @version 1.2.7
207
+ * @version 1.2.9
211
208
  * @author Yusuke Kamiyamane
212
209
  * @license MIT
213
210
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,28 +1,7 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
- "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
14
- }
15
- },
16
- "files": [
17
- "dist",
18
- "LICENSE",
19
- "README.md"
20
- ],
21
- "scripts": {
22
- "build": "tsup",
23
- "prepublishOnly": "npm run build",
24
- "lint": "tsc --noEmit"
25
- },
26
5
  "keywords": [
27
6
  "array",
28
7
  "buffer",
@@ -53,20 +32,41 @@
53
32
  "structured-clone",
54
33
  "typescript"
55
34
  ],
56
- "author": "Yusuke Kamiyamane",
57
- "license": "MIT",
35
+ "homepage": "https://github.com/y14e/bunshin-clone#readme",
36
+ "bugs": {
37
+ "url": "https://github.com/y14e/bunshin-clone/issues"
38
+ },
58
39
  "repository": {
59
40
  "type": "git",
60
41
  "url": "git+https://github.com/y14e/bunshin-clone.git"
61
42
  },
62
- "bugs": {
63
- "url": "https://github.com/y14e/bunshin-clone/issues"
43
+ "license": "MIT",
44
+ "author": "Yusuke Kamiyamane",
45
+ "type": "module",
46
+ "exports": {
47
+ ".": {
48
+ "types": "./dist/index.d.ts",
49
+ "import": "./dist/index.js",
50
+ "require": "./dist/index.cjs"
51
+ }
52
+ },
53
+ "main": "./dist/index.cjs",
54
+ "module": "./dist/index.js",
55
+ "types": "./dist/index.d.ts",
56
+ "files": [
57
+ "dist",
58
+ "LICENSE",
59
+ "README.md"
60
+ ],
61
+ "scripts": {
62
+ "build": "tsup",
63
+ "lint": "tsc --noEmit",
64
+ "prepublishOnly": "npm run build"
64
65
  },
65
- "homepage": "https://github.com/y14e/bunshin-clone#readme",
66
66
  "devDependencies": {
67
67
  "bun-types": "latest",
68
68
  "tsup": "^8.0.0",
69
- "typescript": "^5.6.0"
69
+ "typescript": "^5.9.3"
70
70
  },
71
71
  "engines": {
72
72
  "node": ">=18"