clone-deep
Advanced tools
Comparing version 0.1.1 to 0.2.0
39
index.js
@@ -12,3 +12,2 @@ 'use strict'; | ||
/** | ||
@@ -20,8 +19,8 @@ * Recursively clone native types. | ||
switch (typeOf(val)) { | ||
case 'object': | ||
return cloneObjectDeep(val, instanceClone); | ||
case 'array': | ||
return cloneArrayDeep(val, instanceClone); | ||
default: | ||
return clone(val); | ||
case 'object': | ||
return cloneObjectDeep(val, instanceClone); | ||
case 'array': | ||
return cloneArrayDeep(val, instanceClone); | ||
default: | ||
return clone(val); | ||
} | ||
@@ -45,6 +44,4 @@ } | ||
function cloneArrayDeep(arr, instanceClone) { | ||
var len = arr.length; | ||
var res = []; | ||
var len = arr.length, res = []; | ||
var i = -1; | ||
while (++i < len) { | ||
@@ -58,12 +55,12 @@ res[i] = cloneDeep(arr[i], instanceClone); | ||
switch (typeOf(val)) { | ||
case 'object': | ||
return cloneObject(val); | ||
case 'array': | ||
return cloneArray(val); | ||
case 'regexp': | ||
return cloneRegExp(val); | ||
case 'date': | ||
return cloneDate(val); | ||
default: | ||
return val; | ||
case 'object': | ||
return cloneObject(val); | ||
case 'array': | ||
return cloneArray(val); | ||
case 'regexp': | ||
return cloneRegExp(val); | ||
case 'date': | ||
return cloneDate(val); | ||
default: | ||
return val; | ||
} | ||
@@ -100,2 +97,2 @@ } | ||
module.exports = cloneDeep; | ||
module.exports = cloneDeep; |
{ | ||
"name": "clone-deep", | ||
"description": "Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/jonschlinkert/clone-deep", | ||
@@ -17,8 +17,23 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/clone-deep/blob/master/LICENSE-MIT" | ||
} | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"for-own": "^0.1.3", | ||
"is-plain-object": "^2.0.1", | ||
"kind-of": "^2.0.0", | ||
"mixin-object": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "^7.0.1" | ||
}, | ||
"keywords": [ | ||
@@ -48,22 +63,3 @@ "array", | ||
"utility" | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.9.1", | ||
"mocha": "*", | ||
"should": "^4.0.4", | ||
"verb": "~0.2.6" | ||
}, | ||
"dependencies": { | ||
"for-own": "^0.1.1", | ||
"is-plain-object": "^0.1.0", | ||
"kind-of": "^0.1.0", | ||
"mixin-object": "^0.1.1" | ||
} | ||
] | ||
} |
@@ -1,21 +0,15 @@ | ||
# clone-deep [![NPM version](https://badge.fury.io/js/clone-deep.png)](http://badge.fury.io/js/clone-deep) | ||
# clone-deep [![NPM version](https://badge.fury.io/js/clone-deep.svg)](http://badge.fury.io/js/clone-deep) [![Build Status](https://travis-ci.org/jonschlinkert/clone-deep.svg)](https://travis-ci.org/jonschlinkert/clone-deep) | ||
> Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. | ||
Based on [mout's](https://github.com/mout/mout) implementation of deepClone. The `instanceClone` function is invoked to clone objects that are not "plain" objects (as defined by [`isPlainObject`](#isPlainObject)) if it is provided. If `instanceClone` is not specified, it will not attempt to clone non-plain objects, and will copy the object reference. | ||
The `instanceClone` function is invoked to clone objects that are not "plain" objects (as defined by [](#isPlainObject)`isPlainObject`) if it is provided. If `instanceClone` is not specified, it will not attempt to clone non-plain objects, and will copy the object reference. | ||
## Install | ||
Install with [npm](npmjs.org): | ||
Install with [npm](https://www.npmjs.com/) | ||
```bash | ||
npm i clone-deep --save-dev | ||
```sh | ||
$ npm i clone-deep --save | ||
``` | ||
## Run tests | ||
```bash | ||
npm test | ||
``` | ||
## Usage | ||
@@ -27,31 +21,25 @@ | ||
### Other javascript/node.js utils | ||
## Other object utils | ||
Other projects that I maintain: | ||
* [assign-deep](https://github.com/jonschlinkert/assign-deep): Deeply assign the enumerable properties of source objects to a destination object. | ||
* [extend-shallow](https://github.com/jonschlinkert/extend-shallow): Extend an object with the properties of additional objects. node.js/javascript util. | ||
* [for-in](https://github.com/jonschlinkert/for-in): Iterate over the own and inherited enumerable properties of an objecte, and return an object… [more](https://github.com/jonschlinkert/for-in) | ||
* [for-own](https://github.com/jonschlinkert/for-own): Iterate over the own enumerable properties of an object, and return an object with properties… [more](https://github.com/jonschlinkert/for-own) | ||
* [is-plain-object](https://github.com/jonschlinkert/is-plain-object): Returns true if an object was created by the `Object` constructor. | ||
* [merge-deep](https://github.com/jonschlinkert/merge-deep): Recursively merge values in a javascript object. | ||
* [mixin-deep](https://github.com/jonschlinkert/mixin-deep): Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. | ||
* [mixin-object](https://github.com/jonschlinkert/mixin-object): Mixin the own and inherited properties of other objects onto the first object. Pass an… [more](https://github.com/jonschlinkert/mixin-object) | ||
- [assemble](https://github.com/jonschlinkert/assemble) | ||
- [verb](https://github.com/jonschlinkert/verb) | ||
- [less.js](https://github.com/jonschlinkert/less.js) | ||
- [handlebars-helpers](https://github.com/jonschlinkert/handlebars-helpers) | ||
- [arr](https://github.com/jonschlinkert/arr) | ||
- [arr-diff](https://github.com/jonschlinkert/arr-diff) | ||
- [array-last](https://github.com/jonschlinkert/array-last) | ||
- [array-slice](https://github.com/jonschlinkert/array-slice) | ||
- [array-sum](https://github.com/jonschlinkert/array-sum) | ||
- [arrayify-compact](https://github.com/jonschlinkert/arrayify-compact) | ||
- [compact-object](https://github.com/jonschlinkert/compact-object) | ||
- [delete](https://github.com/jonschlinkert/delete) | ||
- [for-in](https://github.com/jonschlinkert/for-in) | ||
- [for-own](https://github.com/jonschlinkert/for-own) | ||
- [has-any](https://github.com/jonschlinkert/has-any) | ||
- [has-value](https://github.com/jonschlinkert/has-value) | ||
- [is-number](https://github.com/jonschlinkert/is-number) | ||
- [is-plain-object](https://github.com/jonschlinkert/is-plain-object) | ||
- [mixin-deep](https://github.com/jonschlinkert/mixin-deep) | ||
- [mixin-object](https://github.com/jonschlinkert/mixin-object) | ||
- [object-length](https://github.com/jonschlinkert/object-length) | ||
- [omit-empty](https://github.com/jonschlinkert/omit-empty) | ||
- [reduce-object](https://github.com/jonschlinkert/reduce-object) | ||
## Running tests | ||
Install dev dependencies: | ||
```sh | ||
$ npm i -d && npm test | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/clone-deep/issues/new) | ||
## Author | ||
@@ -64,8 +52,13 @@ | ||
Based on [mout's](https://github.com/mout/mout) implementation of deepClone. | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert, contributors. | ||
Released under the MIT license | ||
Copyright © 2014-2015 [Jon Schlinkert](https://github.com/jonschlinkert) | ||
Released under the MIT license. | ||
*** | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 02, 2014._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on June 29, 2015._ | ||
<!-- deps:helper-lookup-deps --> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
6916
4
80
62
+ Addedfor-in@0.1.8(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-plain-object@1.0.02.0.4(transitive)
+ Addedisobject@0.2.03.0.1(transitive)
+ Addedkind-of@2.0.1(transitive)
+ Addedmixin-object@1.0.0(transitive)
- Removedis-plain-object@0.1.0(transitive)
- Removedkind-of@0.1.2(transitive)
- Removedmixin-object@0.1.1(transitive)
Updatedfor-own@^0.1.3
Updatedis-plain-object@^2.0.1
Updatedkind-of@^2.0.0
Updatedmixin-object@^1.0.0