Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-lin committed Jan 10, 2012
0 parents commit 9445f5d
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules
*.sock
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
support
test
examples
*.sock
3 changes: 3 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1 / 2012-01-10

- Initial release
9 changes: 9 additions & 0 deletions Readme.md
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
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require( './lib/node.extend' );
101 changes: 101 additions & 0 deletions lib/node.extend.js
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;
10 changes: 10 additions & 0 deletions package.json
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" ]
}

0 comments on commit 9445f5d

Please sign in to comment.