Socket
Socket
Sign inDemoInstall

clone

Package Overview
Dependencies
0
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

34

clone.js

@@ -44,9 +44,11 @@ var clone = (function() {

* (optional - defaults to parent prototype).
* @param `includeNonEnumerable` - set to true if the non-enumerable properties
* should be cloned as well. Non-enumerable properties on the prototype
* chain will be ignored. (optional - false by default)
*/
function clone(parent, circular, depth, prototype) {
var filter;
function clone(parent, circular, depth, prototype, includeNonEnumerable) {
if (typeof circular === 'object') {
depth = circular.depth;
prototype = circular.prototype;
filter = circular.filter;
includeNonEnumerable = circular.includeNonEnumerable;
circular = circular.circular;

@@ -105,2 +107,4 @@ }

return child;
} else if (parent instanceof Error) {
child = Object.create(parent);
} else {

@@ -169,6 +173,30 @@ if (typeof prototype == 'undefined') {

var symbol = symbols[i];
var descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
if (descriptor && !descriptor.enumerable && !includeNonEnumerable) {
continue;
}
child[symbol] = _clone(parent[symbol], depth - 1);
if (!descriptor.enumerable) {
Object.defineProperty(child, symbol, {
enumerable: false
});
}
}
}
if (includeNonEnumerable) {
var allPropertyNames = Object.getOwnPropertyNames(parent);
for (var i = 0; i < allPropertyNames.length; i++) {
var propertyName = allPropertyNames[i];
var descriptor = Object.getOwnPropertyDescriptor(parent, propertyName);
if (descriptor && descriptor.enumerable) {
continue;
}
child[propertyName] = _clone(parent[propertyName], depth - 1);
Object.defineProperty(child, propertyName, {
enumerable: false
});
}
}
return child;

@@ -175,0 +203,0 @@ }

6

package.json

@@ -11,3 +11,3 @@ {

],
"version": "2.0.0",
"version": "2.1.0",
"repository": {

@@ -40,3 +40,5 @@ "type": "git",

"fscherwi (https://fscherwi.github.io)",
"rictic (https://github.com/rictic)"
"rictic (https://github.com/rictic)",
"Martin Jurča (https://github.com/jurca)",
"Misery Lee <miserylee@foxmail.com> (https://github.com/miserylee)"
],

@@ -43,0 +45,0 @@ "license": "MIT",

@@ -7,3 +7,4 @@ # clone

offers foolproof _deep cloning_ of objects, arrays, numbers, strings etc. in JavaScript.
offers foolproof _deep cloning_ of objects, arrays, numbers, strings, maps,
sets, promises, etc. in JavaScript.

@@ -56,6 +57,11 @@

Call `clone` with `circular` set to `false` if you are certain that `obj`
contains no circular references. This will give better performance if needed.
There is no error if `undefined` or `null` is passed as `obj`.
contains no circular references. This will give better performance if
needed. There is no error if `undefined` or `null` is passed as `obj`.
* `depth` -- depth to which the object is to be cloned (optional,
defaults to infinity)
* `prototype` -- sets the prototype to be used when cloning an object.
(optional, defaults to parent prototype).
* `includeNonEnumerable` -- set to `true` if the non-enumerable properties
should be cloned as well. Non-enumerable properties on the prototype chain
will be ignored. (optional, defaults to `false`)

@@ -97,2 +103,41 @@ `clone.clonePrototype(obj)`

## Changelog
### v2.1.0
#### 2016-11-22
- Add support for cloning Errors
- Exclude non-enumerable symbol-named object properties from cloning
- Add option to include non-enumerable own properties of objects
### v2.0.0
#### 2016-09-28
- Add support for cloning ES6 Maps, Sets, Promises, and Symbols
### v1.0.2
#### 2015-03-25
- Fix call on getRegExpFlags
- Refactor utilities
- Refactor test suite
### v1.0.1
#### 2015-03-04
- Fix nodeunit version
- Directly call getRegExpFlags
### v1.0.0
#### 2015-02-10
- Improve browser support
- Improve browser testability
- Move helper methods to private namespace
## Caveat

@@ -113,3 +158,3 @@

Copyright © 2011-2015 [Paul Vorbach](http://paul.vorba.ch/) and
Copyright © 2011-2016 [Paul Vorbach](http://paul.vorba.ch/) and
[contributors](https://github.com/pvorb/node-clone/graphs/contributors).

@@ -116,0 +161,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc