Comparing version 0.5.3 to 0.5.4
@@ -301,7 +301,17 @@ /** | ||
var clone; | ||
if ('function' === typeof obj) { | ||
clone = obj; | ||
// <!-- Check when and if we need this --> | ||
// clone = function() { return obj.apply(clone, arguments); }; | ||
} | ||
else { | ||
clone = (Object.prototype.toString.call(obj) === '[object Array]') ? [] : {}; | ||
} | ||
var clone = (Object.prototype.toString.call(obj) === '[object Array]') ? [] : {}; | ||
for (var i in obj) { | ||
var value; | ||
// if ('function' === typeof obj[i]) { | ||
// value = function() { return obj[i].apply(clone, arguments); }; | ||
// } | ||
// It is not NULL and it is an object | ||
@@ -512,3 +522,3 @@ if (obj[i] && 'object' === typeof obj[i]) { | ||
* @param {object} o The object to dissect | ||
* @param {string|array} select The selection of properties to remove | ||
* @param {string|array} remove The selection of properties to remove | ||
* @return {object} out The subobject with the properties from the parent one | ||
@@ -515,0 +525,0 @@ * |
{ | ||
"name": "JSUS", | ||
"description": "JavaScript UtilS. Collection of general purpose functions. JSUS helps!", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"keywords": [ "util", "general", "array", "eval", "time", "date", "object", "nodeGame"], | ||
@@ -6,0 +6,0 @@ "author": "Stefano Balietti <futur.dorko@gmail.com>", |
@@ -37,6 +37,15 @@ var util = require('util'); | ||
var obj_func = { | ||
a: 0, | ||
b: function (arg1, arg2) { | ||
return arg1 + arg2; | ||
}, | ||
c: 3, | ||
}; | ||
var array_simple = [1,2,3]; | ||
var array_complex = [1,array_simple, 3]; | ||
var array_complex = [1, array_simple, 3]; | ||
var array_with_null = [1,null,3]; | ||
var array_falsy = [1,false,3]; | ||
var array_func = [1, obj_func.b, 3]; | ||
@@ -53,3 +62,3 @@ // Based on the properties of the objects above | ||
describe('#clone() arrays', function() { | ||
describe('#clone() arrays', function() { | ||
@@ -60,2 +69,3 @@ var copy_simple = JSUS.clone(array_simple); | ||
var copy_falsy = JSUS.clone(array_falsy); | ||
var copy_func = JSUS.clone(array_func); | ||
@@ -102,2 +112,16 @@ // SIMPLE | ||
// FUNC | ||
it('should return the copy of an object containing functions', function(){ | ||
copy_func.should.eql(array_func); | ||
}); | ||
it('cloned functions should return the same value', function(){ | ||
copy_func[1](1,1).should.be.eql(array_func[1](1,1)); | ||
}); | ||
it('modification to the copy of an object containing functions should not affect the original one', function(){ | ||
copy_func[1] = 'foo'; | ||
copy_func[1].should.not.be.equal(array_func[1]); | ||
}); | ||
@@ -112,2 +136,3 @@ }); | ||
var copy_falsy = JSUS.clone(obj_falsy); | ||
var copy_func = JSUS.clone(obj_func) | ||
@@ -154,5 +179,42 @@ // SIMPLE | ||
// FUNC | ||
it('should return the copy of an object containing functions', function(){ | ||
copy_func.should.eql(obj_func); | ||
}); | ||
it('cloned functions should return the same value', function(){ | ||
copy_func.b(1,1).should.be.eql(obj_func.b(1,1)); | ||
}); | ||
it('modification to the copy of an object containing functions should not affect the original one', function(){ | ||
copy_func.b = 'foo'; | ||
copy_func.b.should.not.be.equal(obj_func.b); | ||
}); | ||
}); | ||
describe('#clone() functions', function() { | ||
var clone_func = JSUS.clone(obj_func.b); | ||
console.log(clone_func.toString()) | ||
// FUNC | ||
it('should return the copy of an object containing functions', function(){ | ||
clone_func.should.be.eql(obj_func.b); | ||
}); | ||
it('cloned functions should return the same value', function(){ | ||
clone_func(1,1).should.be.eql(obj_func.b(1,1)); | ||
}); | ||
it('modification to the copy of an object containing functions should not affect the original one', function(){ | ||
clone_func = function(a,b) {return a-b;}; | ||
clone_func.should.not.be.equal(obj_func.b); | ||
}); | ||
}); | ||
// Merging in SIMPLE | ||
@@ -220,2 +282,21 @@ /////////////////////////////////////////////////////// | ||
describe('#merge() obj with functions values in SIMPLE', function() { | ||
var simple_func = JSUS.merge(obj_simple, obj_func); | ||
// Merge null in simple | ||
it('should merge the second in the first object', function(){ | ||
simple_func.should.eql(obj_func); | ||
}); | ||
it('modification to the merged object should affect any of the merging ones', function(){ | ||
checkClone(simple_func, obj_simple, obj_func); | ||
}); | ||
it('merged functions should return the same value', function(){ | ||
simple_func.b(1,1).should.be.eql(obj_func.b(1,1)); | ||
}); | ||
}); | ||
// Merging SIMPLE into other objects | ||
@@ -222,0 +303,0 @@ /////////////////////////////////////////////////////// |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
117518
24
3750
3