combine-3c023bda.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Cesium - https://github.com/CesiumGS/cesium
  3. *
  4. * Copyright 2011-2020 Cesium Contributors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Columbus View (Pat. Pend.)
  19. *
  20. * Portions licensed separately.
  21. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  22. */
  23. define(['exports', './defaultValue-81eec7ed'], (function (exports, defaultValue) { 'use strict';
  24. /**
  25. * Merges two objects, copying their properties onto a new combined object. When two objects have the same
  26. * property, the value of the property on the first object is used. If either object is undefined,
  27. * it will be treated as an empty object.
  28. *
  29. * @example
  30. * const object1 = {
  31. * propOne : 1,
  32. * propTwo : {
  33. * value1 : 10
  34. * }
  35. * }
  36. * const object2 = {
  37. * propTwo : 2
  38. * }
  39. * const final = Cesium.combine(object1, object2);
  40. *
  41. * // final === {
  42. * // propOne : 1,
  43. * // propTwo : {
  44. * // value1 : 10
  45. * // }
  46. * // }
  47. *
  48. * @param {Object} [object1] The first object to merge.
  49. * @param {Object} [object2] The second object to merge.
  50. * @param {Boolean} [deep=false] Perform a recursive merge.
  51. * @returns {Object} The combined object containing all properties from both objects.
  52. *
  53. * @function
  54. */
  55. function combine(object1, object2, deep) {
  56. deep = defaultValue.defaultValue(deep, false);
  57. const result = {};
  58. const object1Defined = defaultValue.defined(object1);
  59. const object2Defined = defaultValue.defined(object2);
  60. let property;
  61. let object1Value;
  62. let object2Value;
  63. if (object1Defined) {
  64. for (property in object1) {
  65. if (object1.hasOwnProperty(property)) {
  66. object1Value = object1[property];
  67. if (
  68. object2Defined &&
  69. deep &&
  70. typeof object1Value === "object" &&
  71. object2.hasOwnProperty(property)
  72. ) {
  73. object2Value = object2[property];
  74. if (typeof object2Value === "object") {
  75. result[property] = combine(object1Value, object2Value, deep);
  76. } else {
  77. result[property] = object1Value;
  78. }
  79. } else {
  80. result[property] = object1Value;
  81. }
  82. }
  83. }
  84. }
  85. if (object2Defined) {
  86. for (property in object2) {
  87. if (
  88. object2.hasOwnProperty(property) &&
  89. !result.hasOwnProperty(property)
  90. ) {
  91. object2Value = object2[property];
  92. result[property] = object2Value;
  93. }
  94. }
  95. }
  96. return result;
  97. }
  98. exports.combine = combine;
  99. }));
  100. //# sourceMappingURL=combine-3c023bda.js.map