validate.js 3.4 KB

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