Socket
Book a DemoInstallSign in
Socket

klon

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

klon

JavaScript helper for deep cloning and deep merging objects as efficiently as possible. Supports and clones complex native objects as well as circular references.

latest
Source
npmnpm
Version
0.11.0
Version published
Maintainers
1
Created
Source

klon

Build status npm version MIT License

JavaScript helper for deep cloning and deep merging objects as efficiently as possible. Supports and clones complex native objects as well as circular references. Is also capable of replacing circular references with a string containing "[Circular]".

Installation

npm install klon

Usage

clone(source[, destination][, breakCircular]);

source is the object to be copied.

destination (optional) is the new object, where all properties from source will be copied to.

var klon = require('klon'),
	myObject1 = {
		a: 1,
		b: 2,
		c: {
			u: 14
		}
	},
	myObject2 = {
		c: [
			{ d: new Date() },
			{ e: "Hello" },
			{ f: "Hello" }
		]
	};

// Clone
var newObject1 = klon(myObject1);

// Extend newObject1 with myObject2
klon(myObject2, newObject1)

// Merge two objects into a new one
var newObject3 = klon(newObject2, klon(newObject1, {}) );

// Clone and break circular references
var newObject4 = klon(myObject1, {}, true);

License

MIT

Keywords

clone

FAQs

Package last updated on 21 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts