validate.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _default_config;
  6. function _load_default_config() {
  7. return _default_config = _interopRequireDefault(require('./default_config'));
  8. }
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  12. *
  13. * This source code is licensed under the MIT license found in the
  14. * LICENSE file in the root directory of this source tree.
  15. *
  16. *
  17. */
  18. const _validate = (config, options) => {
  19. let hasDeprecationWarnings = false;
  20. for (const key in config) {
  21. if (options.deprecatedConfig && key in options.deprecatedConfig && typeof options.deprecate === 'function') {
  22. const isDeprecatedKey = options.deprecate(config, key, options.deprecatedConfig, options);
  23. hasDeprecationWarnings = hasDeprecationWarnings || isDeprecatedKey;
  24. } else if (hasOwnProperty.call(options.exampleConfig, key)) {
  25. if (typeof options.condition === 'function' && typeof options.error === 'function' && !options.condition(config[key], options.exampleConfig[key])) {
  26. options.error(key, config[key], options.exampleConfig[key], options);
  27. }
  28. } else {
  29. options.unknown && options.unknown(config, options.exampleConfig, key, options);
  30. }
  31. }
  32. return { hasDeprecationWarnings };
  33. };
  34. const validate = (config, options) => {
  35. _validate(options, (_default_config || _load_default_config()).default); // validate against jest-validate config
  36. const defaultedOptions = Object.assign({}, (_default_config || _load_default_config()).default, options, { title: Object.assign({}, (_default_config || _load_default_config()).default.title, options.title) });
  37. var _validate2 = _validate(config, defaultedOptions);
  38. const hasDeprecationWarnings = _validate2.hasDeprecationWarnings;
  39. return {
  40. hasDeprecationWarnings,
  41. isValid: true
  42. };
  43. };
  44. exports.default = validate;