mergeOptions.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3. function mergeOptions(parent, child) {
  4. Object.keys(parent).forEach(function (key) {
  5. var val = parent[key];
  6. var _val = child[key];
  7. if (Array.isArray(_val)) {
  8. return false;
  9. }
  10. if (child[key] === undefined) {
  11. child[key] = parent[key];
  12. }
  13. if (_typeof(val) === 'object' && _typeof(_val) === 'object') {
  14. child[key] = Object.assign({}, _val, val);
  15. } else if (typeof val === 'function' && typeof _val === 'function') {
  16. child[key] = function () {
  17. for (var _len = arguments.length, p = new Array(_len), _key = 0; _key < _len; _key++) {
  18. p[_key] = arguments[_key];
  19. }
  20. val.apply(this, p);
  21. _val.apply(this, p);
  22. };
  23. }
  24. });
  25. }
  26. module.exports = mergeOptions;