ae61842dd82a2acf524fd6d4671ad8b74a9e2bb3c62ebb14702c0199bdf9eda399cd92f0b54bca2e967c04e2cb73748e5a82abb2f3da3452559d09b6eed262 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import isFunction from '../utils/is-function';
  2. import extend from '../utils/extend';
  3. import isObject from '../utils/is-object';
  4. import hasOwnProp from '../utils/has-own-prop';
  5. export function set (config) {
  6. var prop, i;
  7. for (i in config) {
  8. prop = config[i];
  9. if (isFunction(prop)) {
  10. this[i] = prop;
  11. } else {
  12. this['_' + i] = prop;
  13. }
  14. }
  15. this._config = config;
  16. // Lenient ordinal parsing accepts just a number in addition to
  17. // number + (possibly) stuff coming from _ordinalParseLenient.
  18. this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source);
  19. }
  20. export function mergeConfigs(parentConfig, childConfig) {
  21. var res = extend({}, parentConfig), prop;
  22. for (prop in childConfig) {
  23. if (hasOwnProp(childConfig, prop)) {
  24. if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
  25. res[prop] = {};
  26. extend(res[prop], parentConfig[prop]);
  27. extend(res[prop], childConfig[prop]);
  28. } else if (childConfig[prop] != null) {
  29. res[prop] = childConfig[prop];
  30. } else {
  31. delete res[prop];
  32. }
  33. }
  34. }
  35. for (prop in parentConfig) {
  36. if (hasOwnProp(parentConfig, prop) &&
  37. !hasOwnProp(childConfig, prop) &&
  38. isObject(parentConfig[prop])) {
  39. // make sure changes to properties don't modify parent config
  40. res[prop] = extend({}, res[prop]);
  41. }
  42. }
  43. return res;
  44. }