forked from dreamerslab/node.extend
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9445f5d
Showing
7 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
node_modules | ||
*.sock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
support | ||
test | ||
examples | ||
*.sock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 / 2012-01-10 | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# node.extend | ||
|
||
Port of jQuery.extend that **actually works** on node.js | ||
|
||
## License | ||
|
||
Copyright 2011, John Resig | ||
Dual licensed under the MIT or GPL Version 2 licenses. | ||
http://jquery.org/license |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require( './lib/node.extend' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/*! | ||
* node.extend | ||
* Copyright 2011, John Resig | ||
* Dual licensed under the MIT or GPL Version 2 licenses. | ||
* http://jquery.org/license | ||
* | ||
* @fileoverview | ||
* Port of jQuery.extend that actually works on node.js | ||
*/ | ||
function isPlainObject( obj ){ | ||
var has_own_constructor, has_is_property_of_method, key; | ||
|
||
if( !obj || {}.toString.call( obj ) !== '[object Object]' || obj.nodeType || obj.setInterval ){ | ||
return false; | ||
} | ||
|
||
has_own_constructor = hasOwnProperty.call( obj, 'constructor' ); | ||
has_is_property_of_method = hasOwnProperty.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. | ||
for( key in obj ){} | ||
|
||
return key === undefined || hasOwnProperty.call( obj, key ); | ||
}; | ||
|
||
function extend () { | ||
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; | ||
} | ||
|
||
// Handle case when target is a string or something (possible in deep copy) | ||
if( typeof target !== 'object' && typeof target !== 'function' ){ | ||
target = {}; | ||
} | ||
|
||
// extend jQuery itself if only one argument is passed | ||
if( length === i ){ | ||
target = this; | ||
--i; | ||
} | ||
|
||
for( ; i < length; i++ ){ | ||
// Only deal with non-null/undefined values | ||
if(( options = arguments[ i ]) != 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; | ||
}; | ||
|
||
|
||
|
||
extend.version = '0.0.1'; | ||
|
||
|
||
|
||
module.exports = extend; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name" : "node.extend", | ||
"version" : "0.0.1", | ||
"description": "Port of jQuery.extend that actually works on node.js", | ||
"keywords": [ "extend", "jQuery", "jQuery extend", "clone", "copy", "inherit" ], | ||
"author": "dreamerslab <ben@dreamerslab.com>", | ||
"dependencies": {}, | ||
"main": "index", | ||
"engines" : [ "node >= 0.4.0" ] | ||
} |