"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/extend/index.js" (11 Apr 2017, 2266 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict';
    2 
    3 var hasOwn = Object.prototype.hasOwnProperty;
    4 var toStr = Object.prototype.toString;
    5 
    6 var isArray = function isArray(arr) {
    7     if (typeof Array.isArray === 'function') {
    8         return Array.isArray(arr);
    9     }
   10 
   11     return toStr.call(arr) === '[object Array]';
   12 };
   13 
   14 var isPlainObject = function isPlainObject(obj) {
   15     if (!obj || toStr.call(obj) !== '[object Object]') {
   16         return false;
   17     }
   18 
   19     var hasOwnConstructor = hasOwn.call(obj, 'constructor');
   20     var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
   21     // Not own constructor property must be Object
   22     if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
   23         return false;
   24     }
   25 
   26     // Own properties are enumerated firstly, so to speed up,
   27     // if last one is own, then all properties are own.
   28     var key;
   29     for (key in obj) {/**/}
   30 
   31     return typeof key === 'undefined' || hasOwn.call(obj, key);
   32 };
   33 
   34 module.exports = function extend() {
   35     var options, name, src, copy, copyIsArray, clone,
   36         target = arguments[0],
   37         i = 1,
   38         length = arguments.length,
   39         deep = false;
   40 
   41     // Handle a deep copy situation
   42     if (typeof target === 'boolean') {
   43         deep = target;
   44         target = arguments[1] || {};
   45         // skip the boolean and the target
   46         i = 2;
   47     } else if ((typeof target !== 'object' && typeof target !== 'function') || target == null) {
   48         target = {};
   49     }
   50 
   51     for (; i < length; ++i) {
   52         options = arguments[i];
   53         // Only deal with non-null/undefined values
   54         if (options != null) {
   55             // Extend the base object
   56             for (name in options) {
   57                 src = target[name];
   58                 copy = options[name];
   59 
   60                 // Prevent never-ending loop
   61                 if (target !== copy) {
   62                     // Recurse if we're merging plain objects or arrays
   63                     if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
   64                         if (copyIsArray) {
   65                             copyIsArray = false;
   66                             clone = src && isArray(src) ? src : [];
   67                         } else {
   68                             clone = src && isPlainObject(src) ? src : {};
   69                         }
   70 
   71                         // Never move original objects, clone them
   72                         target[name] = extend(deep, clone, copy);
   73 
   74                     // Don't bring in undefined values
   75                     } else if (typeof copy !== 'undefined') {
   76                         target[name] = copy;
   77                     }
   78                 }
   79             }
   80         }
   81     }
   82 
   83     // Return the modified object
   84     return target;
   85 };
   86