Comparing version 0.5.0 to 0.6.0
@@ -0,1 +1,6 @@ | ||
# 0.6.0 / 2015-12-29 | ||
- fixed #7 | ||
- added customizer argument | ||
# 0.5.0 / 2015-04-11 | ||
@@ -2,0 +7,0 @@ |
{ | ||
"name": "deepcopy", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"author": "sasa+1 <sasaplus1@gmail.com>", | ||
@@ -9,3 +9,3 @@ "contributors": [ | ||
"description": "deep copy for any data", | ||
"main": "./deepcopy.js", | ||
"main": "./index.js", | ||
"license": "MIT", | ||
@@ -17,24 +17,45 @@ "readmeFilename": "README.md", | ||
}, | ||
"directories": { | ||
"test": "test/" | ||
}, | ||
"scripts": { | ||
"bower": "bower install", | ||
"fix": "fixjsstyle --flagfile .closurelinter -r .", | ||
"lint": "gjslint --flagfile .closurelinter -r .", | ||
"minify": "uglifyjs ./deepcopy.js --comments '@license' -cm -r deepcopy -o ./deepcopy.min.js", | ||
"power": "espower ./test/test.js > ./test/test.pwr.js", | ||
"test": "mocha ./test/test.js", | ||
"testem": "testem", | ||
"travis": "testem ci --launch Firefox,PhantomJS" | ||
"babel": "babel --out-dir ./lib ./src", | ||
"build": "npm ru clean && npm ru babel && npm ru compile && npm ru minify", | ||
"clean": "npm ru rimraf -- ./build ./lib", | ||
"compile": "npm ru webpack -- --output-filename ./build/deepcopy.js", | ||
"develop": " parallelshell 'npm ru babel -- -w' 'npm ru compile -- -w' 'npm ru minify -- -w'", | ||
"eslint": "eslint", | ||
"karma": "karma", | ||
"lint": "npm ru eslint -- --ext .js .", | ||
"minify": "npm ru webpack -- --optimize-minimize --output-filename ./build/deepcopy.min.js", | ||
"mocha": "mocha", | ||
"posttest": "npm ru karma -- start --single-run --browsers Chrome,Firefox,Safari", | ||
"prepublish": "npm ru build", | ||
"rimraf": "rimraf", | ||
"test": "npm ru mocha", | ||
"travis": "npm ru mocha", | ||
"webpack": "webpack --colors --display-error-details --progress" | ||
}, | ||
"devDependencies": { | ||
"bower": "~1.4", | ||
"espower-cli": "~0.2", | ||
"intelli-espower-loader": "~0.6", | ||
"mocha": "~2.2", | ||
"power-assert": "~0.10", | ||
"testem": "~0.7", | ||
"uglify-js": "~2.4" | ||
"babel": "5.8.34", | ||
"babel-eslint": "4.1.6", | ||
"babel-loader": "5.3.3", | ||
"babel-plugin-espower": "1.0.1", | ||
"coffee-script": "^1.10.0", | ||
"eslint": "^1.10.3", | ||
"eslint-config-sasaplus1": "git://github.com/sasaplus1-prototype/eslint-config-sasaplus1.git", | ||
"espower-babel": "3.3.0", | ||
"karma": "^0.13.15", | ||
"karma-chrome-launcher": "^0.2.2", | ||
"karma-firefox-launcher": "^0.1.7", | ||
"karma-mocha": "^0.2.1", | ||
"karma-safari-launcher": "^0.1.1", | ||
"karma-webpack": "^1.7.0", | ||
"mocha": "^2.3.4", | ||
"parallelshell": "^2.0.0", | ||
"power-assert": "^1.2.0", | ||
"rimraf": "^2.4.4", | ||
"webpack": "^1.12.9" | ||
}, | ||
"engines": { | ||
"node": "^4.2.3", | ||
"npm": "^2.14.7" | ||
} | ||
} |
163
README.md
@@ -6,10 +6,11 @@ # deepcopy.js | ||
[![NPM version](https://badge.fury.io/js/deepcopy.svg)](http://badge.fury.io/js/deepcopy) | ||
[![Bower version](https://badge.fury.io/bo/deepcopy.svg)](http://badge.fury.io/bo/deepcopy) | ||
deep copy for any data | ||
## Playground | ||
[REPL powered by Tonic](https://tonicdev.com/npm/deepcopy) | ||
## Installation | ||
### npm | ||
```sh | ||
@@ -19,8 +20,2 @@ $ npm install deepcopy | ||
### bower | ||
```sh | ||
$ bower install deepcopy | ||
``` | ||
## Usage | ||
@@ -31,3 +26,3 @@ | ||
```js | ||
var deepcopy = require('deepcopy'); | ||
var deepcopy = require("deepcopy"); | ||
``` | ||
@@ -41,65 +36,54 @@ | ||
define `deepcopy` by `define()` if using AMD loader. | ||
### Example | ||
otherwise `deepcopy` export to global. | ||
basic usage: | ||
### Example | ||
```js | ||
var data, shallow, deep; | ||
var base, copy; | ||
data = { | ||
objects: { | ||
array: [ | ||
null, undefined, new Date, /deepcopy/ig | ||
], | ||
object: { | ||
number: NaN, | ||
string: 'A', | ||
boolean: true | ||
}, | ||
to: null | ||
} | ||
base = { | ||
desserts: [ | ||
{ name: "cake" }, | ||
{ name: "ice cream" }, | ||
{ name: "pudding" } | ||
] | ||
}; | ||
// circular reference | ||
data.objects.to = data; | ||
copy = deepcopy(base); | ||
base.desserts = null; | ||
// shallow copy and deep copy | ||
shallow = data; | ||
deep = deepcopy(data); | ||
console.log(base); | ||
// { desserts: null } | ||
console.log(copy); | ||
// { desserts: [ { name: 'cake' }, { name: 'ice cream' }, { name: 'pudding' } ] } | ||
``` | ||
// remove entry | ||
delete data.objects; | ||
customize deepcopy: | ||
// results | ||
console.log(data); | ||
// {} | ||
console.log(shallow); | ||
// {} | ||
console.log(require('util').inspect(deep, { depth: null })); | ||
// { objects: | ||
// { array: | ||
// [ null, | ||
// undefined, | ||
// Sat Jan 10 2015 03:18:32 GMT+0900 (JST), | ||
// /deepcopy/gi ], | ||
// object: { number: NaN, string: 'A', boolean: true }, | ||
// to: [Circular] } } | ||
``` | ||
```js | ||
var data, deep; | ||
function MyClass(id) { | ||
this._id = id; | ||
} | ||
data = { object: {} }; | ||
data.object[Symbol.for('sym')] = 123; | ||
var base, copy; | ||
deep = deepcopy(data); | ||
base = { | ||
myClasses: [ | ||
new MyClass(1), | ||
new MyClass(2), | ||
new MyClass(3) | ||
] | ||
}; | ||
delete data.object; | ||
copy = deepcopy(base, function(target) { | ||
if (target.constructor === MyClass) { | ||
return new MyClass(target._id); | ||
} | ||
}); | ||
base.myClasses = null; | ||
console.log(data.object); | ||
// undefined | ||
console.log(deep.object[Symbol.for('sym')]); | ||
// 123 | ||
console.log(base); | ||
// { myClasses: null } | ||
console.log(copy); | ||
// { myClasses: [ MyClass { _id: 1 }, MyClass { _id: 2 }, MyClass { _id: 3 } ] } | ||
``` | ||
@@ -109,34 +93,33 @@ | ||
### deepcopy(value) | ||
### deepcopy(value[, customizer]) | ||
* `value` | ||
* `*` - copy target value | ||
* `return` | ||
* `*` - deep copied value | ||
- `value` | ||
- `*` - target value | ||
- `customizer` | ||
- `Function` - customize function | ||
- `return` | ||
- `*` - copied value | ||
return deep copied value. | ||
support types are below: | ||
supported types are below: | ||
- Number | ||
- String | ||
- Boolean | ||
- Null | ||
- Undefined | ||
- Function | ||
- shallow copy if it is native function | ||
- Date | ||
- RegExp | ||
- Array | ||
- support recursive copy | ||
- also can copy if it has circular reference | ||
- Object | ||
- support recursive copy | ||
- also can copy if it has circular reference | ||
- Buffer (node.js only) | ||
- Symbol | ||
* Number | ||
* String | ||
* Boolean | ||
* Null | ||
* Undefined | ||
* Function (shallow copy) | ||
* Date | ||
* RegExp | ||
* Array | ||
* recursive copy | ||
* also can copy if it has circular reference | ||
* Object | ||
* recursive copy | ||
* also can copy if it has circular reference | ||
* Buffer (node.js only) | ||
* Symbol | ||
## Test | ||
### node.js | ||
```sh | ||
@@ -147,13 +130,5 @@ $ npm install | ||
### browser | ||
```sh | ||
$ npm install | ||
$ npm run bower | ||
$ npm run testem | ||
``` | ||
## Contributors | ||
* [kjirou](https://github.com/kjirou) | ||
- [kjirou](https://github.com/kjirou) | ||
@@ -160,0 +135,0 @@ ## License |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
0
32988
19
14
785
132
3