7733e70d8deb1c5a71404a09380a9f493449f7617be1a47b8cc4079eeacbff556b7870f0293ae63da3614b17cd05d05a94ea37c2bca7b287caee8e53adf7be 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. if (hasOwnProp(config, i)) {
  9. prop = config[i];
  10. if (isFunction(prop)) {
  11. this[i] = prop;
  12. } else {
  13. this['_' + i] = prop;
  14. }
  15. }
  16. }
  17. this._config = config;
  18. // Lenient ordinal parsing accepts just a number in addition to
  19. // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
  20. // TODO: Remove "ordinalParse" fallback in next major release.
  21. this._dayOfMonthOrdinalParseLenient = new RegExp(
  22. (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
  23. '|' +
  24. /\d{1,2}/.source
  25. );
  26. }
  27. export function mergeConfigs(parentConfig, childConfig) {
  28. var res = extend({}, parentConfig),
  29. prop;
  30. for (prop in childConfig) {
  31. if (hasOwnProp(childConfig, prop)) {
  32. if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
  33. res[prop] = {};
  34. extend(res[prop], parentConfig[prop]);
  35. extend(res[prop], childConfig[prop]);
  36. } else if (childConfig[prop] != null) {
  37. res[prop] = childConfig[prop];
  38. } else {
  39. delete res[prop];
  40. }
  41. }
  42. }
  43. for (prop in parentConfig) {
  44. if (
  45. hasOwnProp(parentConfig, prop) &&
  46. !hasOwnProp(childConfig, prop) &&
  47. isObject(parentConfig[prop])
  48. ) {
  49. // make sure changes to properties don't modify parent config
  50. res[prop] = extend({}, res[prop]);
  51. }
  52. }
  53. return res;
  54. }