Deepcopy.js
deep copy data
Install / Use
/learn @sasaplus1/Deepcopy.jsREADME
deepcopy.js
deep copy data
[!CAUTION] This package is no longer maintained. For most deep cloning needs, consider using the native structuredClone() function, which is now available in modern JavaScript environments.
Installation
npm
$ npm install deepcopy
Usage
node.js
JavaScript
const deepcopy = require('deepcopy');
TypeScript
import * as deepcopy from 'deepcopy';
browser
<script src="deepcopy.min.js"></script>
Example
basic usage:
const src = {
desserts: [
{ name: 'cake' },
{ name: 'ice cream' },
{ name: 'pudding' }
]
};
const dist = deepcopy(src);
src.desserts = null;
console.log(src); // { desserts: null }
console.log(dist); // { desserts: [ { name: 'cake' }, { name: 'ice cream' }, { name: 'pudding' } ] }
customize deepcopy:
function MyClass(id) {
this._id = id;
}
const src = {
myClasses: [
new MyClass(1),
new MyClass(2),
new MyClass(3)
]
};
const dest = deepcopy(base, {
customizer(value) {
if (target.constructor === MyClass) {
return new MyClass(target._id);
}
}
});
src.myClasses = null;
console.log(src); // { myClasses: null }
console.log(dest); // { myClasses: [ MyClass { _id: 1 }, MyClass { _id: 2 }, MyClass { _id: 3 } ] }
Functions
deepcopy(value[, options])
value*- target value
optionsObject|FunctionObject- pass optionsFunction- use as customize function
return*- copied value
Supported types and copy operation
|type |operation | | |:-----------------|:-----------|:-------------------------| |ArrayBuffer |deep copy | | |Boolean |deep copy | | |Buffer |deep copy |node.js only | |DataView |deep copy | | |Date |deep copy | | |Number |deep copy | | |RegExp |deep copy | | |String |deep copy | | |Float32Array |deep copy | | |Float64Array |deep copy | | |Int16Array |deep copy | | |Int32Array |deep copy | | |Int8Array |deep copy | | |Uint16Array |deep copy | | |Uint32Array |deep copy | | |Uint8Array |deep copy | | |Uint8ClampedArray |deep copy | | |boolean |deep copy | | |null |deep copy | | |number |deep copy | | |string |deep copy | | |symbol |deep copy | | |undefined |deep copy | | |Arguments |deep copy |recursively, copy as Array| |Array |deep copy |recursively | |Map |deep copy |recursively | |Object |deep copy |recursively | |Set |deep copy |recursively | |Array Iterator |shallow copy| | |Map Iterator |shallow copy| | |Promise |shallow copy| | |Set Iterator |shallow copy| | |String Iterator |shallow copy| | |function |shallow copy| | |global |shallow copy|window, global, self, etc.| |WeakMap |shallow copy| | |WeakSet |shallow copy| |
Contributors
License
The MIT license.
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
