You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

options.js 845B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. var objUtils = require("./util/object");
  3. function getOptions(options, defaults)
  4. {
  5. if ( objUtils.isPlainObject(options) )
  6. {
  7. var newOptions = {};
  8. for (var i in defaults)
  9. {
  10. if ( defaults.hasOwnProperty(i) )
  11. {
  12. if (options[i] !== undefined)
  13. {
  14. newOptions[i] = mergeOption(options[i], defaults[i]);
  15. }
  16. else
  17. {
  18. newOptions[i] = defaults[i];
  19. }
  20. }
  21. }
  22. return newOptions;
  23. }
  24. else
  25. {
  26. return defaults;
  27. }
  28. }
  29. function mergeOption(newValues, defaultValues)
  30. {
  31. if (defaultValues instanceof Object && newValues instanceof Object)
  32. {
  33. if (defaultValues instanceof Array && newValues instanceof Array)
  34. {
  35. return defaultValues.concat(newValues);
  36. }
  37. else
  38. {
  39. return objUtils.shallowMerge(newValues, defaultValues);
  40. }
  41. }
  42. return newValues;
  43. }
  44. module.exports = getOptions;