bunshin-clone 1.2.0 → 1.2.1
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 +26 -29
- package/dist/index.d.cts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +26 -26
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,34 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
// src/index.ts
|
|
6
4
|
var EMPTY_OPTIONS = {};
|
|
7
5
|
var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
8
|
-
function bunshinClone(source, options) {
|
|
9
|
-
return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
|
|
10
|
-
}
|
|
11
|
-
function cloneWithDescriptors(node, options, refs) {
|
|
12
|
-
const result = Object.create(Object.getPrototypeOf(node));
|
|
13
|
-
refs.set(node, result);
|
|
14
|
-
const descs = Object.getOwnPropertyDescriptors(node);
|
|
15
|
-
forEachOwnKey(descs, (key) => {
|
|
16
|
-
if (isUnsafeKey(key)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const desc = { ...descs[key] };
|
|
20
|
-
if ("value" in desc) {
|
|
21
|
-
desc.value = clone(desc.value, options, refs);
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
Object.defineProperty(result, key, desc);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
if (options.strictDescriptors) {
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
return result;
|
|
6
|
+
function bunshinClone(source, options, refs) {
|
|
7
|
+
return clone(source, options ?? EMPTY_OPTIONS, refs ?? /* @__PURE__ */ new WeakMap());
|
|
32
8
|
}
|
|
33
9
|
function clone(node, options, refs) {
|
|
34
10
|
if (!isObject(node)) {
|
|
@@ -184,6 +160,28 @@ function cloneError(value, options, refs) {
|
|
|
184
160
|
}
|
|
185
161
|
return result;
|
|
186
162
|
}
|
|
163
|
+
function cloneWithDescriptors(node, options, refs) {
|
|
164
|
+
const result = Object.create(Object.getPrototypeOf(node));
|
|
165
|
+
refs.set(node, result);
|
|
166
|
+
const descs = Object.getOwnPropertyDescriptors(node);
|
|
167
|
+
forEachOwnKey(descs, (key) => {
|
|
168
|
+
if (isUnsafeKey(key)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const desc = { ...descs[key] };
|
|
172
|
+
if ("value" in desc) {
|
|
173
|
+
desc.value = clone(desc.value, options, refs);
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
Object.defineProperty(result, key, desc);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (options.strictDescriptors) {
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
187
185
|
function forEachOwnKey(object, fn) {
|
|
188
186
|
for (const key of Object.keys(object)) {
|
|
189
187
|
fn(key);
|
|
@@ -211,12 +209,11 @@ function isUnsafeKey(key) {
|
|
|
211
209
|
* High-performance deep clone utility with descriptor support.
|
|
212
210
|
* Handles circular ref and complex built-in types.
|
|
213
211
|
*
|
|
214
|
-
* @version 1.2.
|
|
212
|
+
* @version 1.2.1
|
|
215
213
|
* @author Yusuke Kamiyamane
|
|
216
214
|
* @license MIT
|
|
217
215
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
218
216
|
* @see {@link https://github.com/y14e/bunshin-clone}
|
|
219
217
|
*/
|
|
220
218
|
|
|
221
|
-
exports
|
|
222
|
-
exports.default = bunshinClone;
|
|
219
|
+
module.exports = bunshinClone;
|
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.
|
|
6
|
+
* @version 1.2.1
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -13,9 +13,7 @@ interface BunshinCloneOptions {
|
|
|
13
13
|
readonly preserveDescriptors?: boolean;
|
|
14
14
|
readonly strictDescriptors?: boolean;
|
|
15
15
|
}
|
|
16
|
-
type Object$1 = Record<PropertyKey, unknown>;
|
|
17
16
|
type Refs = WeakMap<object, unknown>;
|
|
18
|
-
declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions): T;
|
|
19
|
-
declare function cloneWithDescriptors<T extends Object$1>(node: T, options: BunshinCloneOptions, refs: Refs): T;
|
|
17
|
+
declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions, refs?: Refs): T;
|
|
20
18
|
|
|
21
|
-
export { type BunshinCloneOptions,
|
|
19
|
+
export { type BunshinCloneOptions, bunshinClone as default };
|
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.
|
|
6
|
+
* @version 1.2.1
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -13,9 +13,7 @@ interface BunshinCloneOptions {
|
|
|
13
13
|
readonly preserveDescriptors?: boolean;
|
|
14
14
|
readonly strictDescriptors?: boolean;
|
|
15
15
|
}
|
|
16
|
-
type Object$1 = Record<PropertyKey, unknown>;
|
|
17
16
|
type Refs = WeakMap<object, unknown>;
|
|
18
|
-
declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions): T;
|
|
19
|
-
declare function cloneWithDescriptors<T extends Object$1>(node: T, options: BunshinCloneOptions, refs: Refs): T;
|
|
17
|
+
declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions, refs?: Refs): T;
|
|
20
18
|
|
|
21
|
-
export { type BunshinCloneOptions,
|
|
19
|
+
export { type BunshinCloneOptions, bunshinClone as default };
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
var EMPTY_OPTIONS = {};
|
|
3
3
|
var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
4
|
-
function bunshinClone(source, options) {
|
|
5
|
-
return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
|
|
6
|
-
}
|
|
7
|
-
function cloneWithDescriptors(node, options, refs) {
|
|
8
|
-
const result = Object.create(Object.getPrototypeOf(node));
|
|
9
|
-
refs.set(node, result);
|
|
10
|
-
const descs = Object.getOwnPropertyDescriptors(node);
|
|
11
|
-
forEachOwnKey(descs, (key) => {
|
|
12
|
-
if (isUnsafeKey(key)) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const desc = { ...descs[key] };
|
|
16
|
-
if ("value" in desc) {
|
|
17
|
-
desc.value = clone(desc.value, options, refs);
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
Object.defineProperty(result, key, desc);
|
|
21
|
-
} catch (error) {
|
|
22
|
-
if (options.strictDescriptors) {
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return result;
|
|
4
|
+
function bunshinClone(source, options, refs) {
|
|
5
|
+
return clone(source, options ?? EMPTY_OPTIONS, refs ?? /* @__PURE__ */ new WeakMap());
|
|
28
6
|
}
|
|
29
7
|
function clone(node, options, refs) {
|
|
30
8
|
if (!isObject(node)) {
|
|
@@ -180,6 +158,28 @@ function cloneError(value, options, refs) {
|
|
|
180
158
|
}
|
|
181
159
|
return result;
|
|
182
160
|
}
|
|
161
|
+
function cloneWithDescriptors(node, options, refs) {
|
|
162
|
+
const result = Object.create(Object.getPrototypeOf(node));
|
|
163
|
+
refs.set(node, result);
|
|
164
|
+
const descs = Object.getOwnPropertyDescriptors(node);
|
|
165
|
+
forEachOwnKey(descs, (key) => {
|
|
166
|
+
if (isUnsafeKey(key)) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const desc = { ...descs[key] };
|
|
170
|
+
if ("value" in desc) {
|
|
171
|
+
desc.value = clone(desc.value, options, refs);
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
Object.defineProperty(result, key, desc);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if (options.strictDescriptors) {
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
183
|
function forEachOwnKey(object, fn) {
|
|
184
184
|
for (const key of Object.keys(object)) {
|
|
185
185
|
fn(key);
|
|
@@ -207,11 +207,11 @@ function isUnsafeKey(key) {
|
|
|
207
207
|
* High-performance deep clone utility with descriptor support.
|
|
208
208
|
* Handles circular ref and complex built-in types.
|
|
209
209
|
*
|
|
210
|
-
* @version 1.2.
|
|
210
|
+
* @version 1.2.1
|
|
211
211
|
* @author Yusuke Kamiyamane
|
|
212
212
|
* @license MIT
|
|
213
213
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
214
214
|
* @see {@link https://github.com/y14e/bunshin-clone}
|
|
215
215
|
*/
|
|
216
216
|
|
|
217
|
-
export {
|
|
217
|
+
export { bunshinClone as default };
|