combine-7cf28d88.js 3.1 KB

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