pax_global_header 0000666 0000000 0000000 00000000064 12413033502 0014503 g ustar 00root root 0000000 0000000 52 comment=1766f482fcf9ca83e07ad6fbeaa079e649d5db0c
node-extend-2.0.0/ 0000775 0000000 0000000 00000000000 12413033502 0013714 5 ustar 00root root 0000000 0000000 node-extend-2.0.0/.gitignore 0000664 0000000 0000000 00000000014 12413033502 0015677 0 ustar 00root root 0000000 0000000 node_modules node-extend-2.0.0/.jscs.json 0000664 0000000 0000000 00000003625 12413033502 0015635 0 ustar 00root root 0000000 0000000 {
"additionalRules": [],
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"],
"disallowSpaceAfterKeywords": [],
"requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true },
"requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true },
"requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true },
"disallowSpacesInsideParentheses": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowQuotedKeysInObjects": "allButReserved",
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"requireSpaceAfterPrefixUnaryOperators": [],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforePostfixUnaryOperators": [],
"disallowSpaceBeforeBinaryOperators": [],
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"disallowSpaceAfterBinaryOperators": [],
"disallowImplicitTypeConversion": ["binary", "string"],
"disallowKeywords": ["with", "eval"],
"requireKeywordsOnNewLine": [],
"disallowKeywordsOnNewLine": ["else"],
"requireLineFeedAtFileEnd": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"excludeFiles": ["node_modules/**", "vendor/**"],
"disallowMultipleLineStrings": true,
"requireDotNotation": true,
"requireParenthesesAroundIIFE": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": {
"escape": true,
"mark": "'"
}
}
node-extend-2.0.0/.npmignore 0000664 0000000 0000000 00000000004 12413033502 0015705 0 ustar 00root root 0000000 0000000 test node-extend-2.0.0/.travis.yml 0000664 0000000 0000000 00000000466 12413033502 0016033 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- "0.11"
- "0.10"
- "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"
node-extend-2.0.0/LICENSE 0000664 0000000 0000000 00000002071 12413033502 0014721 0 ustar 00root root 0000000 0000000 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.
node-extend-2.0.0/README.md 0000664 0000000 0000000 00000004470 12413033502 0015200 0 ustar 00root root 0000000 0000000 [![Build Status][travis-svg]][travis-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
# extend() for Node.js [![Version Badge][npm-version-png]][npm-url]
`node-extend` is a port of the classic extend() method from jQuery. It behaves as you expect. It is simple, tried and true.
## Installation
This package is available on [npm][npm-url] as: `extend`
``` sh
npm install extend
```
## Usage
**Syntax:** extend **(** [`deep`], `target`, `object1`, [`objectN`] **)**
*Extend one object with one or more others, returning the modified object.*
Keep in mind that the target object will be modified, and will be returned from extend().
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)
If set, the merge becomes recursive (i.e. deep copy).
* `target` *Object*
The object to extend.
* `object1` *Object*
The object that will be merged into the first.
* `objectN` *Object* (Optional)
More objects to merge into the first.
## License
`node-extend` is licensed under the [MIT License][mit-license-url].
## Acknowledgements
All credit to the jQuery authors for perfecting this amazing utility.
Ported to Node.js by [Stefan Thomas][github-justmoon] with contributions by [Jonathan Buchanan][github-insin] and [Jordan Harband][github-ljharb].
[travis-svg]: https://travis-ci.org/justmoon/node-extend.svg
[travis-url]: https://travis-ci.org/justmoon/node-extend
[npm-url]: https://npmjs.org/package/extend
[mit-license-url]: http://opensource.org/licenses/MIT
[github-justmoon]: https://github.com/justmoon
[github-insin]: https://github.com/insin
[github-ljharb]: https://github.com/ljharb
[npm-version-png]: http://vb.teelaun.ch/justmoon/node-extend.svg
[deps-svg]: https://david-dm.org/justmoon/node-extend.svg
[deps-url]: https://david-dm.org/justmoon/node-extend
[dev-deps-svg]: https://david-dm.org/justmoon/node-extend/dev-status.svg
[dev-deps-url]: https://david-dm.org/justmoon/node-extend#info=devDependencies
node-extend-2.0.0/component.json 0000664 0000000 0000000 00000001105 12413033502 0016606 0 ustar 00root root 0000000 0000000 {
"name": "extend",
"author": "Stefan Thomas (http://www.justmoon.net)",
"version": "2.0.0",
"description": "Port of jQuery.extend for node.js and the browser.",
"scripts": [
"index.js"
],
"contributors": [
{
"name": "Jordan Harband",
"url": "https://github.com/ljharb"
}
],
"keywords": [
"extend",
"clone",
"merge"
],
"repository" : {
"type": "git",
"url": "https://github.com/justmoon/node-extend.git"
},
"dependencies": {
},
"devDependencies": {
"tape" : "~3.0.0",
"covert": "~0.4.0",
"jscs": "~1.6.2"
}
}
node-extend-2.0.0/index.js 0000664 0000000 0000000 00000004147 12413033502 0015367 0 ustar 00root root 0000000 0000000 var hasOwn = Object.prototype.hasOwnProperty;
var toString = Object.prototype.toString;
var undefined;
var isPlainObject = function isPlainObject(obj) {
'use strict';
if (!obj || toString.call(obj) !== '[object Object]') {
return false;
}
var has_own_constructor = hasOwn.call(obj, 'constructor');
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) {
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) {}
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;
// Handle a deep copy situation
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 == null) {
target = {};
}
for (; i < length; ++i) {
options = arguments[i];
// Only deal with non-null/undefined values
if (options != null) {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];
// Prevent never-ending loop
if (target === copy) {
continue;
}
// Recurse if we're merging plain objects or arrays
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);
// Don't bring in undefined values
} else if (copy !== undefined) {
target[name] = copy;
}
}
}
}
// Return the modified object
return target;
};
node-extend-2.0.0/package.json 0000664 0000000 0000000 00000001406 12413033502 0016203 0 ustar 00root root 0000000 0000000 {
"name": "extend",
"author": "Stefan Thomas (http://www.justmoon.net)",
"version": "2.0.0",
"description": "Port of jQuery.extend for node.js and the browser",
"main": "index",
"scripts": {
"test": "npm run lint && node test/index.js && npm run coverage-quiet",
"coverage": "covert test/index.js",
"coverage-quiet": "covert test/index.js --quiet",
"lint": "jscs *.js */*.js"
},
"contributors": [
{
"name": "Jordan Harband",
"url": "https://github.com/ljharb"
}
],
"keywords": [
"extend",
"clone",
"merge"
],
"repository": {
"type": "git",
"url": "https://github.com/justmoon/node-extend.git"
},
"dependencies": {},
"devDependencies": {
"tape": "~3.0.0",
"covert": "~1.0.0",
"jscs": "~1.6.2"
}
}
node-extend-2.0.0/test/ 0000775 0000000 0000000 00000000000 12413033502 0014673 5 ustar 00root root 0000000 0000000 node-extend-2.0.0/test/index.js 0000664 0000000 0000000 00000034644 12413033502 0016353 0 ustar 00root root 0000000 0000000 var extend = require('../index');
var test = require('tape');
var str = 'me a test';
var int = 10;
var arr = [1, 'what', new Date(81, 8, 4)];
var date = new Date(81, 4, 13);
var Foo = function () {};
var obj = {
str: str,
int: int,
arr: arr,
date: date,
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};
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)
}
}
};
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();
});
test('merge string with number', function (t) {
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.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();
});
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();
});
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),
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};
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();
});
test('merge number with number', function (t) {
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();
});
test('merge number with date', function (t) {
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();
});
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),
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};
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();
});
test('merge array with number', function (t) {
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();
});
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();
});
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();
});
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),
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};
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();
});
test('merge date with number', function (t) {
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();
});
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();
});
test('merge date with date', function (t) {
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();
});
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),
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};
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();
});
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();
});
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();
});
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();
});
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),
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};
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',
foo: new Foo()
};
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),
layer: {
deep: {
int: 42
}
}
};
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',
foo: new Foo()
},
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',
foo: new Foo()
},
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',
foo: new Foo()
},
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',
foo: new Foo()
},
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();
});