deep.clone
Simple and fast deep cloning
A simple NPM package to do simple and fast deep cloning with
JSON.parse
+JSON.stringify
.
Table of contents
Pre-requisite
Install
# Install via NPM $ npm install --save deep.clone
Usage
TypeScript or ES Modules
/** Import project dependencies */; /** Setting up */;; ;
Node.js
/** Import project dependencies */const deepClone = ; /** Setting up */const simpleObject = a: b: c: 1 23 e: f: null d: 'deep';const complexObject = {} b: /test/gi c: 1 2 d: e: f: 111 ; async { const clonedSimpleObject = await ; const clonedComplexObject = await ;};
Browser
ES Modules
IIFE
deno
👉 Check out the deno module at deno_mod/deep_clone.
API Reference
deepClone<T>(target[, options])
target
<T
> Target to be cloned.options
<?Object> Optionally setabsolute: true
for deep cloning complex objects that are not possible withJSON.parse
+JSON.stringify
.absolute
<boolean> If true, deep clone complex objects.
- returns: <Promise<
T
>> Promise which resolves with the deeply cloned target.
This method deeply clones a given target with JSON.parse
+ JSON.stringify
asynchronously by default. Set absolute: true
for deep cloning complex objects that contain Date, RegExp, Function, etc.
deepCloneSync(target[, options])
This methods works the same as deepClone(target[, options])
except that this is the synchronous version.
License
MIT License © Rong Sen Ng