/*
 * Copyright 2014, Gregg Tavares.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Gregg Tavares. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF2 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

"use strict";

var getMissingProperties = function(obj, requiredProperties) {
  var missingProperties = [];
  for (var ii = 0; ii < requiredProperties.length; ++ii) {
    var key = requiredProperties[ii];
    if (obj[key] === undefined) {
      missingProperties.push(key);
    }
  }
  return missingProperties.length > 0 ? missingProperties : undefined;
};

var copyProperties = function(src, dst, opt_overwriteBehavior) {
  Object.keys(src).forEach(function(key) {
    if (opt_overwriteBehavior == 2 && dst[key] !== undefined) {
      return;
    }
    var value = src[key];
    if (value instanceof Array) {
      var newDst = dst[key];
      if (!newDst) {
        newDst = [];
        dst[name] = newDst;
      }
      copyProperties(value, newDst, opt_overwriteBehavior);
    } else if (value instanceof Object) {
      var newDst = dst[key];
      if (!newDst) {
        newDst = {};
        dst[key] = newDst;
      }
      copyProperties(value, newDst, opt_overwriteBehavior);
    } else {
      if (opt_overwriteBehavior == 1 && dst[key] !== undefined) {
        return;
      }
      dst[key] = value;
    }
  });
  return dst;
};

exports.copyProperties = copyProperties;
exports.getMissingProperties = getMissingProperties;


@@ -1583,350 +1583,1359 @@
 %22;%0A%0A
-var getMissingProperties = function(obj, requiredProperties) %7B%0A  var missingProperties = %5B%5D;%0A  for (var ii = 0; ii %3C requiredProperties.length; ++ii) %7B%0A    var key = requiredProperties%5Bii%5D;%0A    if (obj%5Bkey%5D === undefined) %7B%0A      missingProperties.push(key);%0A    %7D%0A  %7D%0A  return missingProperties.length %3E 0 ? missingProperties : undefined;%0A%7D;
+/**%0A * Checks if the required properties exist on an object.%0A *%0A * Example:%0A *%0A *     var requiredProperties = %5B%0A *       %22PATH%22,%0A *       %22MYAPP_SETTING1%22,%0A *       %22MYAPP_SETTING2%22,%0A *     %5D;%0A *     var missing = getMissingProperties(process.env, requiredProperties);%0A *     if (missing) %7B%0A *        console.error(missing.join(%22, %22) + %22 environment variables are not set!%22);%0A *        process.exit(1);%0A *     %7D%0A *%0A * @param %7Bobject%7D obj object to check for required properties%0A * @param %7Bstring%5B%5D%7D requiredProperties properties that are required%0A */%0Avar getMissingProperties = function(obj, requiredProperties) %7B%0A  var missingProperties = %5B%5D;%0A  for (var ii = 0; ii %3C requiredProperties.length; ++ii) %7B%0A    var key = requiredProperties%5Bii%5D;%0A    if (obj%5Bkey%5D === undefined) %7B%0A      missingProperties.push(key);%0A    %7D%0A  %7D%0A  return missingProperties.length %3E 0 ? missingProperties : undefined;%0A%7D;%0A%0A/**%0A * Copy properties from one object to another%0A * @param %7Bobject%7D src object to copy properties from%0A * @param %7Bobject%7D dst object to copy properties to%0A * @param %7Bnumber?%7D opt_overwriteBehavior%0A *     0 = copy everything, making new properties if needed.%0A *     1 = don't copy to dest if dest property doesn't already exist but do recurse%0A *     2 = don't copy to dest if dest property doesn't already exist and don't recurse if dest doesn't exist%0A */
 %0A%0Ava

document misc.js