all files / require-dir-all/lib/ assign.js

100% Statements 12/12
80% Branches 8/10
100% Functions 1/1
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                                16×     14× 14× 14× 14× 14× 21× 21×         14×        
/**
 * Created by alykoshin on 22.01.16.
 */
 
'use strict';
 
/**
 * Node 0.10-0.12 does not supports Object.assign()
 * Instead of modifying Object with polyfill we define private function object_assign()
 *
 * Source below is based upon
 * https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
 *
 * @param {object} target - target object, followed by list of source objects
 * @returns {object}
 */
var object_assign = function (target) {
  if (target === undefined || target === null) {
    throw new TypeError('Cannot convert undefined or null to object');
  }
 
  var output = Object(target);
  for (var index = 1; index < arguments.length; index++) {
    var source = arguments[index];
    Eif (source !== undefined && source !== null) {
      for (var nextKey in source) {
        Eif (source.hasOwnProperty(nextKey)) {
          output[nextKey] = source[nextKey];
        }
      }
    }
  }
  return output;
};
 
 
module.exports = object_assign;