[Pkg-javascript-commits] [node-extend] 02/04: Imported Upstream version 1.3.0

Leo Iannacone l3on-guest at moszumanska.debian.org
Sat Jul 12 17:55:35 UTC 2014


This is an automated email from the git hooks/post-receive script.

l3on-guest pushed a commit to branch master
in repository node-extend.

commit 0a8425ec1fb56077e548dd8f3c6db9057eecf336
Author: Leo Iannacone <l3on at ubuntu.com>
Date:   Sat Jul 12 19:48:38 2014 +0200

    Imported Upstream version 1.3.0
---
 .travis.yml                    |  17 +-
 LICENSE                        |  23 +
 README.md                      |  17 +-
 package.json => component.json |  14 +-
 index.js                       |  58 +--
 package.json                   |  11 +-
 test/index.js                  | 943 ++++++++++++++++++++++-------------------
 7 files changed, 596 insertions(+), 487 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index c99d400..912080a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,18 @@
 language: node_js
 node_js:
+  - "0.11"
   - "0.10"
-  - 0.8
-  - 0.6
+  - "0.9"
+  - "0.8"
+  - "0.6"
+  - "0.4"
+before_install:
+  - '[ "${TRAVIS_NODE_VERSION}" == "0.6" ] || npm install -g npm@~1.4.6'
+matrix:
+  fast_finish: true
+  allow_failures:
+    - node_js: "0.11"
+    - node_js: "0.9"
+    - node_js: "0.6"
+    - node_js: "0.4"
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..e16d6a5
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,23 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Stefan Thomas
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/README.md b/README.md
index ddaee06..715f666 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ npm install extend
 
 ## Usage
 
-**Syntax:** extend **(** [`deep`], `target`, `object1`, [`objectN`] **)** 
+**Syntax:** extend **(** [`deep`], `target`, `object1`, [`objectN`] **)**
 
 *Extend one object with one or more others, returning the modified object.*
 
@@ -22,16 +22,17 @@ Keep in mind that the target object will be modified, and will be returned from
 
 If a boolean true is specified as the first argument, extend performs a deep copy, recursively copying any objects it finds. Otherwise, the copy will share structure with the original object(s).
 Undefined properties are not copied. However, properties inherited from the object's prototype will be copied over.
+Warning: passing `false` as the first argument is not supported.
 
 ### Arguments
 
-* `deep` *Boolean* (optional)  
+* `deep` *Boolean* (optional)
 If set, the merge becomes recursive (i.e. deep copy).
-* `target`	*Object*  
+* `target`	*Object*
 The object to extend.
-* `object1`	*Object*  
+* `object1`	*Object*
 The object that will be merged into the first.
-* `objectN` *Object* (Optional)  
+* `objectN` *Object* (Optional)
 More objects to merge into the first.
 
 ## License
@@ -44,7 +45,7 @@ All credit to the jQuery authors for perfecting this amazing utility.
 
 Ported to Node.js by [Stefan Thomas][5] with contributions by [Jonathan Buchanan][6] and [Jordan Harband][7].
 
-[1]: https://travis-ci.org/justmoon/node-extend.png
+[1]: https://travis-ci.org/justmoon/node-extend.svg
 [2]: https://travis-ci.org/justmoon/node-extend
 [3]: https://npmjs.org/package/extend
 [4]: http://opensource.org/licenses/MIT
@@ -52,8 +53,8 @@ Ported to Node.js by [Stefan Thomas][5] with contributions by [Jonathan Buchanan
 [6]: https://github.com/insin
 [7]: https://github.com/ljharb
 [8]: http://vb.teelaun.ch/justmoon/node-extend.svg
-[9]: https://david-dm.org/justmoon/node-extend.png
+[9]: https://david-dm.org/justmoon/node-extend.svg
 [10]: https://david-dm.org/justmoon/node-extend
-[11]: https://david-dm.org/justmoon/node-extend/dev-status.png
+[11]: https://david-dm.org/justmoon/node-extend/dev-status.svg
 [12]: https://david-dm.org/justmoon/node-extend#info=devDependencies
 
diff --git a/package.json b/component.json
similarity index 70%
copy from package.json
copy to component.json
index 38cb640..378c7f5 100644
--- a/package.json
+++ b/component.json
@@ -1,12 +1,11 @@
 {
 	"name": "extend",
 	"author": "Stefan Thomas <justmoon at members.fsf.org> (http://www.justmoon.net)",
-	"version": "1.2.1",
-	"description": "Port of jQuery.extend for Node.js",
-	"main": "index",
-	"scripts": {
-		"test": "node test/index.js"
-	},
+	"version": "1.3.0",
+	"description": "Port of jQuery.extend for node.js and the browser.",
+	"scripts": [
+		"index.js"
+	],
 	"contributors": [
 		{
 			"name": "Jordan Harband",
@@ -25,7 +24,8 @@
 	"dependencies": {
 	},
 	"devDependencies": {
-		"tape" : "~1.1.0"
+		"tape" : "~2.12.3",
+		"covert": "~0.4.0"
 	}
 }
 
diff --git a/index.js b/index.js
index be7300b..06f3c12 100644
--- a/index.js
+++ b/index.js
@@ -1,73 +1,74 @@
 var hasOwn = Object.prototype.hasOwnProperty;
 var toString = Object.prototype.toString;
+var undefined;
 
-function isPlainObject(obj) {
-	if (!obj || toString.call(obj) !== '[object Object]' || obj.nodeType || obj.setInterval)
+var isPlainObject = function isPlainObject(obj) {
+	"use strict";
+	if (!obj || toString.call(obj) !== '[object Object]' || obj.nodeType || obj.setInterval) {
 		return false;
+	}
 
 	var has_own_constructor = hasOwn.call(obj, 'constructor');
-	var has_is_property_of_method = hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
+	var has_is_property_of_method = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
 	// Not own constructor property must be Object
-	if (obj.constructor && !has_own_constructor && !has_is_property_of_method)
+	if (obj.constructor && !has_own_constructor && !has_is_property_of_method) {
 		return false;
+	}
 
 	// Own properties are enumerated firstly, so to speed up,
 	// if last one is own, then all properties are own.
 	var key;
-	for ( key in obj ) {}
+	for (key in obj) {}
 
-	return key === undefined || hasOwn.call( obj, key );
+	return key === undefined || hasOwn.call(obj, key);
 };
 
 module.exports = function extend() {
+	"use strict";
 	var options, name, src, copy, copyIsArray, clone,
-	    target = arguments[0] || {},
-	    i = 1,
-	    length = arguments.length,
-	    deep = false;
+		target = arguments[0],
+		i = 1,
+		length = arguments.length,
+		deep = false;
 
 	// Handle a deep copy situation
-	if ( typeof target === "boolean" ) {
+	if (typeof target === "boolean") {
 		deep = target;
 		target = arguments[1] || {};
 		// skip the boolean and the target
 		i = 2;
+	} else if (typeof target !== "object" && typeof target !== "function" || target == undefined) {
+			target = {};
 	}
 
-	// Handle case when target is a string or something (possible in deep copy)
-	if ( typeof target !== "object" && typeof target !== "function") {
-		target = {};
-	}
-
-	for ( ; i < length; i++ ) {
+	for (; i < length; ++i) {
 		// Only deal with non-null/undefined values
-		if ( (options = arguments[ i ]) != null ) {
+		if ((options = arguments[i]) != null) {
 			// Extend the base object
-			for ( name in options ) {
-				src = target[ name ];
-				copy = options[ name ];
+			for (name in options) {
+				src = target[name];
+				copy = options[name];
 
 				// Prevent never-ending loop
-				if ( target === copy ) {
+				if (target === copy) {
 					continue;
 				}
 
 				// Recurse if we're merging plain objects or arrays
-				if ( deep && copy && ( isPlainObject(copy) || (copyIsArray = Array.isArray(copy)) ) ) {
-					if ( copyIsArray ) {
+				if (deep && copy && (isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) {
+					if (copyIsArray) {
 						copyIsArray = false;
 						clone = src && Array.isArray(src) ? src : [];
-
 					} else {
 						clone = src && isPlainObject(src) ? src : {};
 					}
 
 					// Never move original objects, clone them
-					target[ name ] = extend( deep, clone, copy );
+					target[name] = extend(deep, clone, copy);
 
 				// Don't bring in undefined values
-				} else if ( copy !== undefined ) {
-					target[ name ] = copy;
+				} else if (copy !== undefined) {
+					target[name] = copy;
 				}
 			}
 		}
@@ -76,3 +77,4 @@ module.exports = function extend() {
 	// Return the modified object
 	return target;
 };
+
diff --git a/package.json b/package.json
index 38cb640..ddcee05 100644
--- a/package.json
+++ b/package.json
@@ -1,11 +1,13 @@
 {
 	"name": "extend",
 	"author": "Stefan Thomas <justmoon at members.fsf.org> (http://www.justmoon.net)",
-	"version": "1.2.1",
-	"description": "Port of jQuery.extend for Node.js",
+	"version": "1.3.0",
+	"description": "Port of jQuery.extend for node.js and the browser",
 	"main": "index",
 	"scripts": {
-		"test": "node test/index.js"
+		"test": "node test/index.js",
+		"coverage": "covert test/index.js",
+		"coverage-quiet": "covert test/index.js --quiet"
 	},
 	"contributors": [
 		{
@@ -25,7 +27,8 @@
 	"dependencies": {
 	},
 	"devDependencies": {
-		"tape" : "~1.1.0"
+		"tape" : "~2.13.2",
+		"covert": "~0.4.0"
 	}
 }
 
diff --git a/test/index.js b/test/index.js
index 1957694..f4fdde5 100644
--- a/test/index.js
+++ b/test/index.js
@@ -7,531 +7,598 @@ var arr = [1, 'what', new Date(81, 8, 4)];
 var date = new Date(81, 4, 13);
 
 var obj = {
-  str: str,
-  int: int,
-  arr: arr,
-  date: date
+	str: str,
+	int: int,
+	arr: arr,
+	date: date,
+	constructor: 'fake',
+	isPrototypeOf: 'not a function'
 };
 
 var deep = {
-  ori: obj,
-  layer: {
-    int: 10,
-    str: 'str',
-    date: new Date(84, 5, 12),
-    arr: [101, 'dude', new Date(82, 10, 4)],
-    deep: {
-      str: obj.str,
-      int: int,
-      arr: obj.arr,
-      date: new Date(81, 7, 4)
-    }
-  }
+	ori: obj,
+	layer: {
+		int: 10,
+		str: 'str',
+		date: new Date(84, 5, 12),
+		arr: [101, 'dude', new Date(82, 10, 4)],
+		deep: {
+			str: obj.str,
+			int: int,
+			arr: obj.arr,
+			date: new Date(81, 7, 4)
+		}
+	}
 };
 
+test('missing arguments', function (t) {
+	t.deepEqual(extend(undefined, { a: 1 }), { a: 1 }, 'missing first argument is second argument');
+	t.deepEqual(extend({ a: 1 }), { a: 1 }, 'missing second argument is first argument');
+	t.deepEqual(extend(true, undefined, { a: 1 }), { a: 1 }, 'deep: missing first argument is second argument');
+	t.deepEqual(extend(true, { a: 1 }), { a: 1 }, 'deep: missing second argument is first argument');
+	t.deepEqual(extend(), {}, 'no arguments is object');
+	t.end();
+});
 
 test('merge string with string', function (t) {
-  var ori = 'what u gonna say';
-  var target = extend(ori, str);
-  var expectedTarget = {
-    '0': 'm',
-    '1': 'e',
-    '2': ' ',
-    '3': 'a',
-    '4': ' ',
-    '5': 't',
-    '6': 'e',
-    '7': 's',
-    '8': 't'
-  };
-
-  t.equal(ori, 'what u gonna say', 'original string 1 is unchanged');
-  t.equal(str, 'me a test', 'original string 2 is unchanged');
-  t.deepEqual(target, expectedTarget, 'string + string is merged object form of string');
-  t.end();
+	var ori = 'what u gonna say';
+	var target = extend(ori, str);
+	var expectedTarget = {
+		'0': 'm',
+		'1': 'e',
+		'2': ' ',
+		'3': 'a',
+		'4': ' ',
+		'5': 't',
+		'6': 'e',
+		'7': 's',
+		'8': 't'
+	};
+
+	t.equal(ori, 'what u gonna say', 'original string 1 is unchanged');
+	t.equal(str, 'me a test', 'original string 2 is unchanged');
+	t.deepEqual(target, expectedTarget, 'string + string is merged object form of string');
+	t.end();
 });
 
 test('merge string with number', function (t) {
-  var ori = 'what u gonna say';
-  var target = extend(ori, 10);
+	var ori = 'what u gonna say';
+	var target = extend(ori, 10);
 
-  t.equal(ori, 'what u gonna say', 'original string is unchanged');
-  t.deepEqual(target, {}, 'string + number is empty object');
+	t.equal(ori, 'what u gonna say', 'original string is unchanged');
+	t.deepEqual(target, {}, 'string + number is empty object');
 
-  t.end();
+	t.end();
 });
 
 test('merge string with array', function (t) {
-  var ori = 'what u gonna say';
-  var target = extend(ori, arr);
-
-  t.equal(ori, 'what u gonna say', 'original string is unchanged');
-  t.deepEqual(arr, [1, 'what', new Date(81, 8, 4)], 'array is unchanged');
-  t.deepEqual(target, {
-    '0' : 1,
-    '1' : 'what',
-    '2' : new Date(81, 8, 4)
-  }, 'string + array is array');
-  t.end();
+	var ori = 'what u gonna say';
+	var target = extend(ori, arr);
+
+	t.equal(ori, 'what u gonna say', 'original string is unchanged');
+	t.deepEqual(arr, [1, 'what', new Date(81, 8, 4)], 'array is unchanged');
+	t.deepEqual(target, {
+		'0' : 1,
+		'1' : 'what',
+		'2' : new Date(81, 8, 4)
+	}, 'string + array is array');
+	t.end();
 });
 
 test('merge string with date', function (t) {
-  var ori = 'what u gonna say';
-  var target = extend(ori, date);
-
-  var testDate = new Date(81, 4, 13);
-  t.equal(ori, 'what u gonna say', 'original string is unchanged');
-  t.deepEqual(date, testDate, 'date is unchanged');
-  t.deepEqual(target, testDate, 'string + date is date');
-  t.end();
+	var ori = 'what u gonna say';
+	var target = extend(ori, date);
+
+	var testDate = new Date(81, 4, 13);
+	t.equal(ori, 'what u gonna say', 'original string is unchanged');
+	t.deepEqual(date, testDate, 'date is unchanged');
+	t.deepEqual(target, testDate, 'string + date is date');
+	t.end();
 });
 
 test('merge string with obj', function (t) {
-  var ori = 'what u gonna say';
-  var target = extend(ori, obj);
-
-  t.equal(ori, 'what u gonna say', 'original string is unchanged');
-  var testObj = {
-    str: 'me a test',
-    int: 10,
-    arr: [1, 'what', new Date(81, 8, 4)],
-    date: new Date(81, 4, 13)
-  };
-  t.deepEqual(obj, testObj, 'original obj is unchanged');
-  t.deepEqual(target, testObj, 'string + obj is obj');
-  t.end();
+	var ori = 'what u gonna say';
+	var target = extend(ori, obj);
+
+	t.equal(ori, 'what u gonna say', 'original string is unchanged');
+	var testObj = {
+		str: 'me a test',
+		int: 10,
+		arr: [1, 'what', new Date(81, 8, 4)],
+		date: new Date(81, 4, 13),
+		constructor: 'fake',
+		isPrototypeOf: 'not a function'
+	};
+	t.deepEqual(obj, testObj, 'original obj is unchanged');
+	t.deepEqual(target, testObj, 'string + obj is obj');
+	t.end();
 });
 
 test('merge number with string', function (t) {
-  var ori = 20;
-  var target = extend(ori, str);
-
-  t.equal(ori, 20, 'number is unchanged');
-  t.equal(str, 'me a test', 'string is unchanged');
-  t.deepEqual(target, {
-    '0': 'm',
-    '1': 'e',
-    '2': ' ',
-    '3': 'a',
-    '4': ' ',
-    '5': 't',
-    '6': 'e',
-    '7': 's',
-    '8': 't'
-  }, 'number + string is object form of string');
-  t.end();
+	var ori = 20;
+	var target = extend(ori, str);
+
+	t.equal(ori, 20, 'number is unchanged');
+	t.equal(str, 'me a test', 'string is unchanged');
+	t.deepEqual(target, {
+		'0': 'm',
+		'1': 'e',
+		'2': ' ',
+		'3': 'a',
+		'4': ' ',
+		'5': 't',
+		'6': 'e',
+		'7': 's',
+		'8': 't'
+	}, 'number + string is object form of string');
+	t.end();
 });
 
 test('merge number with number', function (t) {
-  t.deepEqual(extend(20, 10), {}, 'number + number is empty object');
-  t.end();
+	t.deepEqual(extend(20, 10), {}, 'number + number is empty object');
+	t.end();
 });
 
 test('merge number with array', function (t) {
-  var target = extend(20, arr);
-
-  t.deepEqual(arr, [1, 'what', new Date(81, 8, 4)], 'array is unchanged');
-  t.deepEqual(target, {
-    '0': 1,
-    '1': 'what',
-    '2': new Date(81, 8, 4)
-  }, 'number + arr is object with array contents');
-  t.end();
+	var target = extend(20, arr);
+
+	t.deepEqual(arr, [1, 'what', new Date(81, 8, 4)], 'array is unchanged');
+	t.deepEqual(target, {
+		'0': 1,
+		'1': 'what',
+		'2': new Date(81, 8, 4)
+	}, 'number + arr is object with array contents');
+	t.end();
 });
 
 test('merge number with date', function (t) {
-  var target = extend(20, date);
-  var testDate = new Date(81, 4, 13);
+	var target = extend(20, date);
+	var testDate = new Date(81, 4, 13);
 
-  t.deepEqual(date, testDate, 'original date is unchanged');
-  t.deepEqual(target, testDate, 'number + date is date');
-  t.end();
+	t.deepEqual(date, testDate, 'original date is unchanged');
+	t.deepEqual(target, testDate, 'number + date is date');
+	t.end();
 });
 
 test('merge number with object', function (t) {
-  var target = extend(20, obj);
-  var testObj = {
-    str: 'me a test',
-    int: 10,
-    arr: [ 1, 'what', new Date(81, 8, 4)],
-    date: new Date(81, 4, 13)
-  };
-
-  t.deepEqual(obj, testObj, 'obj is unchanged');
-  t.deepEqual(target, testObj, 'number + obj is obj');
-  t.end();
+	var target = extend(20, obj);
+	var testObj = {
+		str: 'me a test',
+		int: 10,
+		arr: [1, 'what', new Date(81, 8, 4)],
+		date: new Date(81, 4, 13),
+		constructor: 'fake',
+		isPrototypeOf: 'not a function'
+	};
+
+	t.deepEqual(obj, testObj, 'obj is unchanged');
+	t.deepEqual(target, testObj, 'number + obj is obj');
+	t.end();
 });
 
 test('merge array with string', function (t) {
-  var ori = [1, 2, 3, 4, 5, 6];
-  var target = extend(ori, str);
-
-  t.deepEqual(ori, str.split(''), 'array is changed to be an array of string chars');
-  t.equal(str, 'me a test', 'string is unchanged');
-  t.deepEqual(target, {
-    '0': 'm',
-    '1': 'e',
-    '2': ' ',
-    '3': 'a',
-    '4': ' ',
-    '5': 't',
-    '6': 'e',
-    '7': 's',
-    '8': 't'
-  }, 'array + string is object form of string');
-  t.end();
+	var ori = [1, 2, 3, 4, 5, 6];
+	var target = extend(ori, str);
+
+	t.deepEqual(ori, str.split(''), 'array is changed to be an array of string chars');
+	t.equal(str, 'me a test', 'string is unchanged');
+	t.deepEqual(target, {
+		'0': 'm',
+		'1': 'e',
+		'2': ' ',
+		'3': 'a',
+		'4': ' ',
+		'5': 't',
+		'6': 'e',
+		'7': 's',
+		'8': 't'
+	}, 'array + string is object form of string');
+	t.end();
 });
 
 test('merge array with number', function (t) {
-  var ori = [1, 2, 3, 4, 5, 6];
-  var target = extend(ori, 10);
+	var ori = [1, 2, 3, 4, 5, 6];
+	var target = extend(ori, 10);
 
-  t.deepEqual(ori, [1, 2, 3, 4, 5, 6], 'array is unchanged');
-  t.deepEqual(target, ori, 'array + number is array');
-  t.end();
+	t.deepEqual(ori, [1, 2, 3, 4, 5, 6], 'array is unchanged');
+	t.deepEqual(target, ori, 'array + number is array');
+	t.end();
 });
 
 test('merge array with array', function (t) {
-  var ori = [1, 2, 3, 4, 5, 6];
-  var target = extend(ori, arr);
-  var testDate = new Date(81, 8, 4);
-  var expectedTarget = [1, 'what', testDate, 4, 5, 6];
-
-  t.deepEqual(ori, expectedTarget, 'array + array merges arrays; changes first array');
-  t.deepEqual(arr, [1, 'what', testDate], 'second array is unchanged');
-  t.deepEqual(target, expectedTarget, 'array + array is merged array');
-  t.end();
+	var ori = [1, 2, 3, 4, 5, 6];
+	var target = extend(ori, arr);
+	var testDate = new Date(81, 8, 4);
+	var expectedTarget = [1, 'what', testDate, 4, 5, 6];
+
+	t.deepEqual(ori, expectedTarget, 'array + array merges arrays; changes first array');
+	t.deepEqual(arr, [1, 'what', testDate], 'second array is unchanged');
+	t.deepEqual(target, expectedTarget, 'array + array is merged array');
+	t.end();
 });
 
 test('merge array with date', function (t) {
-  var ori = [1, 2, 3, 4, 5, 6];
-  var target = extend(ori, date);
-  var testDate = new Date(81, 4, 13);
-  var testArray = [1, 2, 3, 4, 5, 6];
-
-  t.deepEqual(ori, testArray, 'array is unchanged');
-  t.deepEqual(date, testDate, 'date is unchanged');
-  t.deepEqual(target, testArray, 'array + date is array');
-  t.end();
+	var ori = [1, 2, 3, 4, 5, 6];
+	var target = extend(ori, date);
+	var testDate = new Date(81, 4, 13);
+	var testArray = [1, 2, 3, 4, 5, 6];
+
+	t.deepEqual(ori, testArray, 'array is unchanged');
+	t.deepEqual(date, testDate, 'date is unchanged');
+	t.deepEqual(target, testArray, 'array + date is array');
+	t.end();
 });
 
 test('merge array with object', function (t) {
-  var ori = [1, 2, 3, 4, 5, 6];
-  var target = extend(ori, obj);
-  var testObject = {
-    str: 'me a test',
-    int: 10,
-    arr: [1, 'what', new Date(81, 8, 4)],
-    date: new Date(81, 4, 13)
-  };
-
-  t.deepEqual(obj, testObject, 'obj is unchanged');
-  t.equal(ori.length, 6, 'array has proper length');
-  t.equal(ori.str, obj.str, 'array has obj.str property');
-  t.equal(ori.int, obj.int, 'array has obj.int property');
-  t.deepEqual(ori.arr, obj.arr, 'array has obj.arr property');
-  t.equal(ori.date, obj.date, 'array has obj.date property');
-
-  t.equal(target.length, 6, 'target has proper length');
-  t.equal(target.str, obj.str, 'target has obj.str property');
-  t.equal(target.int, obj.int, 'target has obj.int property');
-  t.deepEqual(target.arr, obj.arr, 'target has obj.arr property');
-  t.equal(target.date, obj.date, 'target has obj.date property');
-  t.end();
+	var ori = [1, 2, 3, 4, 5, 6];
+	var target = extend(ori, obj);
+	var testObject = {
+		str: 'me a test',
+		int: 10,
+		arr: [1, 'what', new Date(81, 8, 4)],
+		date: new Date(81, 4, 13),
+		constructor: 'fake',
+		isPrototypeOf: 'not a function'
+	};
+
+	t.deepEqual(obj, testObject, 'obj is unchanged');
+	t.equal(ori.length, 6, 'array has proper length');
+	t.equal(ori.str, obj.str, 'array has obj.str property');
+	t.equal(ori.int, obj.int, 'array has obj.int property');
+	t.deepEqual(ori.arr, obj.arr, 'array has obj.arr property');
+	t.equal(ori.date, obj.date, 'array has obj.date property');
+
+	t.equal(target.length, 6, 'target has proper length');
+	t.equal(target.str, obj.str, 'target has obj.str property');
+	t.equal(target.int, obj.int, 'target has obj.int property');
+	t.deepEqual(target.arr, obj.arr, 'target has obj.arr property');
+	t.equal(target.date, obj.date, 'target has obj.date property');
+	t.end();
 });
 
 test('merge date with string', function (t) {
-  var ori = new Date(81, 9, 20);
-  var target = extend(ori, str);
-  var testObject = {
-    '0': 'm',
-    '1': 'e',
-    '2': ' ',
-    '3': 'a',
-    '4': ' ',
-    '5': 't',
-    '6': 'e',
-    '7': 's',
-    '8': 't'
-  };
-
-  t.deepEqual(ori, testObject, 'date is changed to object form of string');
-  t.equal(str, 'me a test', 'string is unchanged');
-  t.deepEqual(target, testObject, 'date + string is object form of string');
-  t.end();
+	var ori = new Date(81, 9, 20);
+	var target = extend(ori, str);
+	var testObject = {
+		'0': 'm',
+		'1': 'e',
+		'2': ' ',
+		'3': 'a',
+		'4': ' ',
+		'5': 't',
+		'6': 'e',
+		'7': 's',
+		'8': 't'
+	};
+
+	t.deepEqual(ori, testObject, 'date is changed to object form of string');
+	t.equal(str, 'me a test', 'string is unchanged');
+	t.deepEqual(target, testObject, 'date + string is object form of string');
+	t.end();
 });
 
 test('merge date with number', function (t) {
-  var ori = new Date(81, 9, 20);
-  var target = extend(ori, 10);
+	var ori = new Date(81, 9, 20);
+	var target = extend(ori, 10);
 
-  t.deepEqual(ori, {}, 'date is changed to empty object');
-  t.deepEqual(target, {}, 'date + number is empty object');
-  t.end();
+	t.deepEqual(ori, {}, 'date is changed to empty object');
+	t.deepEqual(target, {}, 'date + number is empty object');
+	t.end();
 });
 
 test('merge date with array', function (t) {
-  var ori = new Date(81, 9, 20);
-  var target = extend(ori, arr);
-  var testDate = new Date(81, 9, 20);
-  var testArray = [1, 'what', new Date(81, 8, 4)];
-
-  t.deepEqual(ori, testDate, 'date is unchanged');
-  t.deepEqual(arr, testArray, 'array is unchanged');
-  t.deepEqual(target, testDate, 'date + array is date');
-  t.end();
+	var ori = new Date(81, 9, 20);
+	var target = extend(ori, arr);
+	var testDate = new Date(81, 9, 20);
+	var testArray = [1, 'what', new Date(81, 8, 4)];
+
+	t.deepEqual(ori, testDate, 'date is unchanged');
+	t.deepEqual(arr, testArray, 'array is unchanged');
+	t.deepEqual(target, testDate, 'date + array is date');
+	t.end();
 });
 
 test('merge date with date', function (t) {
-  var ori = new Date(81, 9, 20);
-  var target = extend(ori, date);
+	var ori = new Date(81, 9, 20);
+	var target = extend(ori, date);
 
-  t.deepEqual(ori, {}, 'date is empty object');
-  t.deepEqual(target, {}, 'date + date is empty object');
-  t.end();
+	t.deepEqual(ori, {}, 'date is empty object');
+	t.deepEqual(target, {}, 'date + date is empty object');
+	t.end();
 });
 
 test('merge date with object', function (t) {
-  var ori = new Date(81, 9, 20);
-  var target = extend(ori, obj);
-  var testDate = new Date(81, 8, 4);
-  var testObject = {
-    str: 'me a test',
-    int: 10,
-    arr: [1, 'what', testDate],
-    date: new Date(81, 4, 13)
-  };
-
-  t.deepEqual(obj, testObject, 'original object is unchanged');
-  t.deepEqual(ori, testObject, 'date becomes original object');
-  t.deepEqual(target, testObject, 'date + object is object');
-  t.end();
+	var ori = new Date(81, 9, 20);
+	var target = extend(ori, obj);
+	var testDate = new Date(81, 8, 4);
+	var testObject = {
+		str: 'me a test',
+		int: 10,
+		arr: [1, 'what', testDate],
+		date: new Date(81, 4, 13),
+		constructor: 'fake',
+		isPrototypeOf: 'not a function'
+	};
+
+	t.deepEqual(obj, testObject, 'original object is unchanged');
+	t.deepEqual(ori, testObject, 'date becomes original object');
+	t.deepEqual(target, testObject, 'date + object is object');
+	t.end();
 });
 
 test('merge object with string', function (t) {
-  var testDate = new Date(81, 7, 26);
-  var ori = {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: testDate
-  };
-  var target = extend(ori, str);
-  var testObj = {
-    '0': 'm',
-    '1': 'e',
-    '2': ' ',
-    '3': 'a',
-    '4': ' ',
-    '5': 't',
-    '6': 'e',
-    '7': 's',
-    '8': 't',
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: testDate
-  };
-
-  t.deepEqual(ori, testObj, 'original object updated');
-  t.equal(str, 'me a test', 'string is unchanged');
-  t.deepEqual(target, testObj, 'object + string is object + object form of string');
-  t.end();
+	var testDate = new Date(81, 7, 26);
+	var ori = {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: testDate
+	};
+	var target = extend(ori, str);
+	var testObj = {
+		'0': 'm',
+		'1': 'e',
+		'2': ' ',
+		'3': 'a',
+		'4': ' ',
+		'5': 't',
+		'6': 'e',
+		'7': 's',
+		'8': 't',
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: testDate
+	};
+
+	t.deepEqual(ori, testObj, 'original object updated');
+	t.equal(str, 'me a test', 'string is unchanged');
+	t.deepEqual(target, testObj, 'object + string is object + object form of string');
+	t.end();
 });
 
 test('merge object with number', function (t) {
-  var ori = {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26)
-  };
-  var testObject = {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26)
-  };
-  var target = extend(ori, 10);
-  t.deepEqual(ori, testObject, 'object is unchanged');
-  t.deepEqual(target, testObject, 'object + number is object');
-  t.end();
+	var ori = {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26)
+	};
+	var testObject = {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26)
+	};
+	var target = extend(ori, 10);
+	t.deepEqual(ori, testObject, 'object is unchanged');
+	t.deepEqual(target, testObject, 'object + number is object');
+	t.end();
 });
 
 test('merge object with array', function (t) {
-  var ori = {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26)
-  };
-  var target = extend(ori, arr);
-  var testObject = {
-    '0': 1,
-    '1': 'what',
-    '2': new Date(81, 8, 4),
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26)
-  };
-
-  t.deepEqual(ori, testObject, 'original object is merged');
-  t.deepEqual(arr, [1, 'what', testObject[2]], 'array is unchanged');
-  t.deepEqual(target, testObject, 'object + array is merged object');
-  t.end();
+	var ori = {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26)
+	};
+	var target = extend(ori, arr);
+	var testObject = {
+		'0': 1,
+		'1': 'what',
+		'2': new Date(81, 8, 4),
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26)
+	};
+
+	t.deepEqual(ori, testObject, 'original object is merged');
+	t.deepEqual(arr, [1, 'what', testObject[2]], 'array is unchanged');
+	t.deepEqual(target, testObject, 'object + array is merged object');
+	t.end();
 });
 
 test('merge object with date', function (t) {
-  var ori = {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26)
-  };
-  var target = extend(ori, date);
-  var testObject = {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26)
-  };
-
-  t.deepEqual(ori, testObject, 'original object is unchanged');
-  t.deepEqual(date, new Date(81, 4, 13), 'date is unchanged');
-  t.deepEqual(target, testObject, 'object + date is object');
-  t.end();
+	var ori = {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26)
+	};
+	var target = extend(ori, date);
+	var testObject = {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26)
+	};
+
+	t.deepEqual(ori, testObject, 'original object is unchanged');
+	t.deepEqual(date, new Date(81, 4, 13), 'date is unchanged');
+	t.deepEqual(target, testObject, 'object + date is object');
+	t.end();
 });
 
 test('merge object with object', function (t) {
-  var ori = {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26),
-    foo: 'bar'
-  };
-  var target = extend(ori, obj);
-  var expectedObj = {
-    str: 'me a test',
-    int: 10,
-    arr: [1, 'what', new Date(81, 8, 4)],
-    date: new Date(81, 4, 13)
-  };
-  var expectedTarget = {
-    str: 'me a test',
-    int: 10,
-    arr: [1, 'what', new Date(81, 8, 4)],
-    date: new Date(81, 4, 13),
-    foo: 'bar'
-  };
-
-  t.deepEqual(obj, expectedObj, 'obj is unchanged');
-  t.deepEqual(ori, expectedTarget, 'original has been merged');
-  t.deepEqual(target, expectedTarget, 'object + object is merged object');
-  t.end();
+	var ori = {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26),
+		foo: 'bar'
+	};
+	var target = extend(ori, obj);
+	var expectedObj = {
+		str: 'me a test',
+		int: 10,
+		arr: [1, 'what', new Date(81, 8, 4)],
+		date: new Date(81, 4, 13),
+		constructor: 'fake',
+		isPrototypeOf: 'not a function'
+	};
+	var expectedTarget = {
+		str: 'me a test',
+		int: 10,
+		arr: [1, 'what', new Date(81, 8, 4)],
+		date: new Date(81, 4, 13),
+		foo: 'bar',
+		constructor: 'fake',
+		isPrototypeOf: 'not a function'
+	};
+
+	t.deepEqual(obj, expectedObj, 'obj is unchanged');
+	t.deepEqual(ori, expectedTarget, 'original has been merged');
+	t.deepEqual(target, expectedTarget, 'object + object is merged object');
+	t.end();
 });
 
 test('deep clone', function (t) {
-  var ori = {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26)
-  };
-  var target = extend(true, ori, deep);
-
-  t.deepEqual(ori, {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26),
-    ori: {
-      str: 'me a test',
-      int: 10,
-      arr: [1, 'what', new Date(81, 8, 4)],
-      date: new Date(81, 4, 13)
-    },
-    layer: {
-      int: 10,
-      str: 'str',
-      date: new Date(84, 5, 12),
-      arr: [101, 'dude', new Date(82, 10, 4)],
-      deep: {
-        str: 'me a test',
-        int: 10,
-        arr: [1, 'what', new Date(81, 8, 4)],
-        date: new Date(81, 7, 4)
-      }
-    }
-  }, 'original object is merged');
-  t.deepEqual(deep, {
-    ori: {
-      str: 'me a test',
-      int: 10,
-      arr: [1, 'what', new Date(81, 8, 4)],
-      date: new Date(81, 4, 13)
-    },
-    layer: {
-      int: 10,
-      str: 'str',
-      date: new Date(84, 5, 12),
-      arr: [101, 'dude', new Date(82, 10, 4)],
-      deep: {
-        str: 'me a test',
-        int: 10,
-        arr: [1, 'what', new Date(81, 8, 4)],
-        date: new Date(81, 7, 4)
-      }
-    }
-  }, 'deep is unchanged');
-  t.deepEqual(target, {
-    str: 'no shit',
-    int: 76,
-    arr: [1, 2, 3, 4],
-    date: new Date(81, 7, 26),
-    ori: {
-      str: 'me a test',
-      int: 10,
-      arr: [1, 'what', new Date(81, 8, 4)],
-      date: new Date(81, 4, 13)
-    },
-    layer: {
-      int: 10,
-      str: 'str',
-      date: new Date(84, 5, 12),
-      arr: [101, 'dude', new Date(82, 10, 4)],
-      deep: {
-        str: 'me a test',
-        int: 10,
-        arr: [1, 'what', new Date(81, 8, 4)],
-        date: new Date(81, 7, 4)
-      }
-    }
-  }, 'deep + object + object is deeply merged object');
-
-  target.layer.deep = 339;
-  t.deepEqual(deep, {
-    ori: {
-      str: 'me a test',
-      int: 10,
-      arr: [1, 'what', new Date(81, 8, 4)],
-      date: new Date(81, 4, 13)
-    },
-    layer: {
-      int: 10,
-      str: 'str',
-      date: new Date(84, 5, 12),
-      arr: [101, 'dude', new Date(82, 10, 4)],
-      deep: {
-        str: 'me a test',
-        int: 10,
-        arr: [1, 'what', new Date(81, 8, 4)],
-        date: new Date(81, 7, 4)
-      }
-    }
-  }, 'deep is unchanged after setting target property');
-  //----- NEVER USE EXTEND WITH THE ABOVE SITUATION ------------------------------
-  t.end();
+	var ori = {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26)
+	};
+	var target = extend(true, ori, deep);
+
+	t.deepEqual(ori, {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26),
+		ori: {
+			str: 'me a test',
+			int: 10,
+			arr: [1, 'what', new Date(81, 8, 4)],
+			date: new Date(81, 4, 13),
+			constructor: 'fake',
+			isPrototypeOf: 'not a function'
+		},
+		layer: {
+			int: 10,
+			str: 'str',
+			date: new Date(84, 5, 12),
+			arr: [101, 'dude', new Date(82, 10, 4)],
+			deep: {
+				str: 'me a test',
+				int: 10,
+				arr: [1, 'what', new Date(81, 8, 4)],
+				date: new Date(81, 7, 4)
+			}
+		}
+	}, 'original object is merged');
+	t.deepEqual(deep, {
+		ori: {
+			str: 'me a test',
+			int: 10,
+			arr: [1, 'what', new Date(81, 8, 4)],
+			date: new Date(81, 4, 13),
+			constructor: 'fake',
+			isPrototypeOf: 'not a function'
+		},
+		layer: {
+			int: 10,
+			str: 'str',
+			date: new Date(84, 5, 12),
+			arr: [101, 'dude', new Date(82, 10, 4)],
+			deep: {
+				str: 'me a test',
+				int: 10,
+				arr: [1, 'what', new Date(81, 8, 4)],
+				date: new Date(81, 7, 4)
+			}
+		}
+	}, 'deep is unchanged');
+	t.deepEqual(target, {
+		str: 'no shit',
+		int: 76,
+		arr: [1, 2, 3, 4],
+		date: new Date(81, 7, 26),
+		ori: {
+			str: 'me a test',
+			int: 10,
+			arr: [1, 'what', new Date(81, 8, 4)],
+			date: new Date(81, 4, 13),
+			constructor: 'fake',
+			isPrototypeOf: 'not a function'
+		},
+		layer: {
+			int: 10,
+			str: 'str',
+			date: new Date(84, 5, 12),
+			arr: [101, 'dude', new Date(82, 10, 4)],
+			deep: {
+				str: 'me a test',
+				int: 10,
+				arr: [1, 'what', new Date(81, 8, 4)],
+				date: new Date(81, 7, 4)
+			}
+		}
+	}, 'deep + object + object is deeply merged object');
+
+	target.layer.deep = 339;
+	t.deepEqual(deep, {
+		ori: {
+			str: 'me a test',
+			int: 10,
+			arr: [1, 'what', new Date(81, 8, 4)],
+			date: new Date(81, 4, 13),
+			constructor: 'fake',
+			isPrototypeOf: 'not a function'
+		},
+		layer: {
+			int: 10,
+			str: 'str',
+			date: new Date(84, 5, 12),
+			arr: [101, 'dude', new Date(82, 10, 4)],
+			deep: {
+				str: 'me a test',
+				int: 10,
+				arr: [1, 'what', new Date(81, 8, 4)],
+				date: new Date(81, 7, 4)
+			}
+		}
+	}, 'deep is unchanged after setting target property');
+	//----- NEVER USE EXTEND WITH THE ABOVE SITUATION ------------------------------
+	t.end();
+});
+
+test('deep clone; arrays are merged', function (t) {
+	var defaults = {
+		arr: [1, 2, 3]
+	};
+	var override = {
+		arr: ["x"]
+	};
+	var expectedTarget = {
+		arr: ["x", 2, 3]
+	};
+
+	var target = extend(true, defaults, override);
+
+	t.deepEqual(target, expectedTarget, 'arrays are merged');
+	t.end();
 });
 
+test('deep clone === false; objects merged normally', function (t) {
+	var defaults = {
+		a: 1
+	};
+	var override = {
+		a: 2
+	};
+	var target = extend(false, defaults, override);
+	t.deepEqual(target, override, 'deep === false handled normally');
+	t.end();
+});
+
+test('pass in null; should create a valid object', function (t) {
+	var override = {
+		a: 1
+	};
+	var target = extend(null, override);
+	t.deepEqual(target, override, 'null object handled normally');
+	t.end();
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-extend.git



More information about the Pkg-javascript-commits mailing list