Comparing version 0.3.1 to 0.3.2
{ | ||
"name": "deepcopy", | ||
"version": "0.3.0", | ||
"version": "0.3.2", | ||
"main": "./deepcopy.min.js", | ||
"ignore": [ | ||
".gitignore", | ||
".npmignore", | ||
".travis.yml" | ||
"**/.*", | ||
"node_modules", | ||
"bower_components" | ||
], | ||
"devDependencies": { | ||
"chai": "~1.6", | ||
"jquery": "~2.0", | ||
"mocha": "~1.9" | ||
"expect": "~0.2", | ||
"mocha": "~1.12" | ||
} | ||
} |
@@ -0,1 +1,6 @@ | ||
# 0.3.2 / 2013-09-08 | ||
- more compressed deepcopy.min.js | ||
- changed from chai to expect.js | ||
# 0.3.1 / 2013-06-12 | ||
@@ -2,0 +7,0 @@ |
@@ -9,3 +9,3 @@ /*! | ||
// fallback of util methods. | ||
// fallback for util methods. | ||
var util = (typeof module !== 'undefined') ? require('util') : (function() { | ||
@@ -42,3 +42,3 @@ | ||
// fallback of Object.keys. | ||
// fallback for Object.keys. | ||
var getKeys = Object.keys || function(object) { | ||
@@ -49,3 +49,3 @@ var keys = [], | ||
if (object === null || typeof object !== 'object') { | ||
throw new TypeError('parameter type is not an object'); | ||
throw new TypeError('parameter type is not an Object'); | ||
} | ||
@@ -73,3 +73,3 @@ | ||
if (!util.isArray(array)) { | ||
throw new TypeError('parameter type is not an array'); | ||
throw new TypeError('parameter type is not an Array'); | ||
} | ||
@@ -113,3 +113,3 @@ | ||
*/ | ||
return (function(target, clone, visited, ref) { | ||
function deepcopy_(target, clone, visited, ref) { | ||
var keys, i, len, key, value, index, object, reference; | ||
@@ -123,4 +123,3 @@ | ||
if (util.isDate(target)) { | ||
return new Date( | ||
Number(target)); | ||
return new Date(Number(target)); | ||
} | ||
@@ -153,3 +152,3 @@ | ||
// not used object variable if target is not reference type. | ||
clone[key] = reference || arguments.callee(value, object, visited, ref); | ||
clone[key] = reference || deepcopy_(value, object, visited, ref); | ||
index = object = reference = null; | ||
@@ -159,3 +158,5 @@ } | ||
return clone; | ||
}(target, clone, visited, ref)); | ||
} | ||
return deepcopy_(target, clone, visited, ref); | ||
} | ||
@@ -162,0 +163,0 @@ |
{ | ||
"name": "deepcopy", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"author": "sasa+1 <sasaplus1@gmail.com>", | ||
"description": "library of deep copy", | ||
"contributors": [ | ||
"kjirou <kjirou.web@gmail.com>" | ||
], | ||
"description": "deep copy for any data", | ||
"main": "./index.js", | ||
@@ -11,19 +14,20 @@ "license": "MIT", | ||
"type": "git", | ||
"url": "https://github.com/sasaplus1/deepcopy.js.git" | ||
"url": "git://github.com/sasaplus1/deepcopy.js.git" | ||
}, | ||
"scripts": { | ||
"bower": "./node_modules/.bin/bower install", | ||
"bower": "bower install", | ||
"fix": "fixjsstyle --strict --nojsdoc -r ./lib -r ./test ./inedx.js", | ||
"lint": "gjslint --strict --nojsdoc -r ./lib -r ./test ./index.js", | ||
"mini": "./node_modules/.bin/uglifyjs ./lib/deepcopy.js --comments -cmr deepcopy -o ./deepcopy.min.js", | ||
"test": "./node_modules/.bin/mocha", | ||
"testem": "./node_modules/.bin/testem ci" | ||
"mini": "uglifyjs ./lib/deepcopy.js --comments -cm -d 'module=void 0' -r deepcopy -o ./deepcopy.min.js", | ||
"test": "mocha", | ||
"testem": "testem ci", | ||
"travis": "testem ci --launch Firefox,PhantomJS" | ||
}, | ||
"devDependencies": { | ||
"bower": "~0.9", | ||
"chai": "~1.6", | ||
"mocha": "~1.10", | ||
"testem": "~0.2", | ||
"uglify-js": "~2.3" | ||
"bower": "~1.2", | ||
"expect.js": "~0.2", | ||
"mocha": "~1.12", | ||
"testem": "~0.4", | ||
"uglify-js": "~2.4" | ||
} | ||
} |
@@ -6,3 +6,3 @@ # deepcopy.js | ||
library of deep copy | ||
deep copy for any data | ||
@@ -13,7 +13,11 @@ ## Installation | ||
$ npm install deepcopy | ||
```sh | ||
$ npm install deepcopy | ||
``` | ||
### bower | ||
$ bower install deepcopy | ||
```sh | ||
$ bower install deepcopy | ||
``` | ||
@@ -94,13 +98,21 @@ ## Usage | ||
$ npm install | ||
$ npm test | ||
```sh | ||
$ npm install | ||
$ npm test | ||
``` | ||
### test for browser | ||
$ npm install | ||
$ npm run-script bower | ||
$ npm run-script testem | ||
```sh | ||
$ npm install | ||
$ npm run-script bower | ||
$ npm run-script testem | ||
``` | ||
## Contributors | ||
* [kjirou](https://github.com/kjirou) | ||
## License | ||
The MIT License. Please see LICENSE file. |
@@ -1,176 +0,93 @@ | ||
var assert, deepcopy; | ||
var expect, deepcopy; | ||
if (typeof module !== 'undefined') { | ||
assert = require('chai').assert; | ||
expect = require('expect.js'); | ||
deepcopy = require('../'); | ||
} else { | ||
assert = chai.assert; | ||
deepcopy = window.deepcopy; | ||
expect = this.expect; | ||
deepcopy = this.deepcopy; | ||
} | ||
suite('deepcopy', function() { | ||
describe('deepcopy', function() { | ||
test('return copy of parameter if parameter is primitive types', function() { | ||
assert.strictEqual( | ||
deepcopy(12345), | ||
12345, | ||
'deepcopy(12345) should be returned 12345'); | ||
assert.strictEqual( | ||
deepcopy('abc'), | ||
'abc', | ||
'deepcopy("abc") should be returned "abc"'); | ||
assert.strictEqual( | ||
deepcopy(true), | ||
true, | ||
'deepcopy(true) should be returned true'); | ||
assert.strictEqual( | ||
deepcopy(null), | ||
null, | ||
'deepcopy(null) should be returned null'); | ||
assert.strictEqual( | ||
deepcopy(void 0), | ||
void 0, | ||
'deepcopy(undefined) should be returned undefined'); | ||
it('should return deep copy if parameter is primitive type', function() { | ||
expect(deepcopy(12345)).to.be(12345); | ||
expect(deepcopy('abc')).to.be('abc'); | ||
expect(deepcopy(true)).to.be(true); | ||
expect(deepcopy(null)).to.be(null); | ||
expect(deepcopy(void 0)).to.be(void 0); | ||
}); | ||
test('return reference if parameter is Function', function() { | ||
var copied = deepcopy(f); | ||
it('should return reference if parameter is Function', function() { | ||
function f() {} | ||
assert.isTrue( | ||
copied instanceof Function, | ||
'instance should be Function'); | ||
assert.strictEqual( | ||
copied, | ||
f, | ||
'deepcopy(function() {}) should be returned function() {} reference'); | ||
expect(deepcopy(f)).to.be(f); | ||
}); | ||
test('return deep copy of Date if parameter is Date', function() { | ||
var date = new Date, | ||
copied = deepcopy(date); | ||
it('should return deep copy if parameter is Date', function() { | ||
var date = new Date; | ||
assert.isTrue( | ||
copied instanceof Date, | ||
'instance should be Date'); | ||
assert.notStrictEqual( | ||
copied, | ||
date, | ||
'deepcopy(date) should not be return date reference'); | ||
assert.deepEqual( | ||
copied, | ||
date, | ||
'deepcopy(date) should be return deep copied date'); | ||
expect(deepcopy(date)).to.eql(date); | ||
}); | ||
test('return deep copy of RegExp if parameter is RegExp', function() { | ||
var regexp = /\x00/gi, | ||
copied = deepcopy(regexp); | ||
it('should return deep copy if parameter is RegExp', function() { | ||
var regexp = /\x00/gi; | ||
assert.isTrue( | ||
copied instanceof RegExp, | ||
'instance should be RegExp'); | ||
assert.notStrictEqual( | ||
copied, | ||
regexp, | ||
'deepcopy(regexp) should not be return regexp reference'); | ||
assert.deepEqual( | ||
copied, | ||
regexp, | ||
'deepcopy(regexp) should be return deep copied regexp'); | ||
expect(deepcopy(regexp)).to.eql(regexp); | ||
}); | ||
test('return deep copy of Array if parameter is Array', function() { | ||
it('should return deep copy if parameter is Array', function() { | ||
var array = [ | ||
12345, | ||
'abc', | ||
false, | ||
null, | ||
void 0, | ||
function() {}, | ||
new Date, | ||
/\x00/ig, | ||
[1, 'a', true, null, void 0, function() {}, new Date, /\x00/ig], | ||
{ | ||
12345, 'abc', true, null, void 0, function() {}, new Date, /\x00/gi, [ | ||
12345, 'abc', true, null, void 0, function() {}, new Date, /\x00/gi | ||
], { | ||
array: [ | ||
1, 'a', true, null, void 0, function() {}, new Date, /\x00/ig | ||
12345, 'abc', true, null, void 0, function() {}, new Date, /\x00/gi | ||
] | ||
} | ||
], | ||
copied = deepcopy(array); | ||
]; | ||
assert.isTrue( | ||
copied instanceof Array, | ||
'instance should be Array'); | ||
assert.notStrictEqual( | ||
copied, | ||
array, | ||
'deepcopy(array) should not be return array reference'); | ||
assert.deepEqual( | ||
copied, | ||
array, | ||
'deepcopy(array) should be return deep copied array'); | ||
expect(deepcopy(array)).to.eql(array); | ||
}); | ||
test('return deep copy of Object if parameter is Object', function() { | ||
it('should return deep copy if parameter is Object', function() { | ||
var object = { | ||
number: 12345, | ||
string: 'abc', | ||
boolean: false, | ||
nil: null, | ||
undef: void 0, | ||
func: function() {}, | ||
num: 12345, | ||
str: 'abc', | ||
bool: true, | ||
null: null, | ||
undefined: void 0, | ||
fn: function() {}, | ||
date: new Date, | ||
regexp: /\x00/ig, | ||
regexp: /\x00/gi, | ||
array: [ | ||
1, 'a', true, null, void 0, function() {}, new Date, /\x00/ig | ||
1, 'a', false, null, void 0, function() {}, new Date, /\x00/gi | ||
], | ||
object: { | ||
a: 1, b: 'a', c: true, d: null, e: void 0, f: function() {} | ||
num: 1, | ||
str: 'a', | ||
bool: false, | ||
null: null, | ||
undefined: void 0, | ||
fn: function() {}, | ||
date: new Date, | ||
regexp: /\x00/gi | ||
} | ||
}, | ||
copied = deepcopy(object); | ||
}; | ||
assert.isTrue( | ||
copied instanceof Object, | ||
'instance should be Object'); | ||
assert.notStrictEqual( | ||
copied, | ||
object, | ||
'deepcopy(object) should not be return object reference'); | ||
assert.deepEqual( | ||
copied, | ||
object, | ||
'deepcopy(object) should be return deep copied object'); | ||
expect(deepcopy(object)).to.eql(object); | ||
}); | ||
// built-in assert module is cannot test object if object has circular | ||
// reference. chai supporting circular reference. | ||
test('return object if parameter has circular reference', function() { | ||
assert.doesNotThrow( | ||
function() { | ||
var object = { value: 1 }, | ||
copied; | ||
it('should return deep copy if parameter has circular reference', function() { | ||
var circular, copy; | ||
object.to = object; | ||
copied = deepcopy(object); | ||
expect(function() { | ||
circular = {}; | ||
circular.to = circular; | ||
copy = deepcopy(circular); | ||
}).to.not.throwException(); | ||
assert.notStrictEqual( | ||
copied, | ||
object, | ||
'deepcopy should not be return object reference'); | ||
assert.strictEqual( | ||
copied, | ||
copied.to, | ||
'deepcopy should be assigned copied.to to copied'); | ||
assert.deepEqual( | ||
copied, | ||
object, | ||
'deepcopy should be return deep copied object'); | ||
}, | ||
'deepcopy should not be threw error if parameter has circular ' + | ||
'reference'); | ||
expect(copy.to).to.be(copy); | ||
}); | ||
}); |
{ | ||
"test_page": "./test/test-deepcopy.html", | ||
"launch_in_ci": [ | ||
"Firefox", | ||
"PhantomJS" | ||
] | ||
"test_page": "./test/test-deepcopy.html" | ||
} |
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
196458
25
6017
116
7
1