utils.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.createDidYouMeanMessage = exports.logValidationWarning = exports.ValidationError = exports.format = exports.WARNING = exports.ERROR = exports.DEPRECATION = undefined;var _chalk;
  2. function _load_chalk() {return _chalk = _interopRequireDefault(require('chalk'));}var _prettyFormat;
  3. function _load_prettyFormat() {return _prettyFormat = _interopRequireDefault(require('pretty-format'));}var _leven;
  4. function _load_leven() {return _leven = _interopRequireDefault(require('leven'));}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
  5. const BULLET = (_chalk || _load_chalk()).default.bold('\u25cf'); /**
  6. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  7. *
  8. * This source code is licensed under the MIT license found in the
  9. * LICENSE file in the root directory of this source tree.
  10. *
  11. *
  12. */const DEPRECATION = exports.DEPRECATION = `${BULLET} Deprecation Warning`;const ERROR = exports.ERROR = `${BULLET} Validation Error`;const WARNING = exports.WARNING = `${BULLET} Validation Warning`;const format = exports.format = value => typeof value === 'function' ? value.toString() :
  13. (0, (_prettyFormat || _load_prettyFormat()).default)(value, { min: true });
  14. class ValidationError extends Error {
  15. constructor(name, message, comment) {
  16. super();
  17. comment = comment ? '\n\n' + comment : '\n';
  18. this.name = '';
  19. this.message = (_chalk || _load_chalk()).default.red((_chalk || _load_chalk()).default.bold(name) + ':\n\n' + message + comment);
  20. Error.captureStackTrace(this, () => {});
  21. }}exports.ValidationError = ValidationError;
  22. const logValidationWarning = exports.logValidationWarning = (
  23. name,
  24. message,
  25. comment) =>
  26. {
  27. comment = comment ? '\n\n' + comment : '\n';
  28. console.warn((_chalk || _load_chalk()).default.yellow((_chalk || _load_chalk()).default.bold(name) + ':\n\n' + message + comment));
  29. };
  30. const createDidYouMeanMessage = exports.createDidYouMeanMessage = (
  31. unrecognized,
  32. allowedOptions) =>
  33. {
  34. const suggestion = allowedOptions.find(option => {
  35. const steps = (0, (_leven || _load_leven()).default)(option, unrecognized);
  36. return steps < 3;
  37. });
  38. return suggestion ? `Did you mean ${(_chalk || _load_chalk()).default.bold(format(suggestion))}?` : '';
  39. };