1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.logValidationWarning =
|
7 | exports.formatPrettyObject =
|
8 | exports.format =
|
9 | exports.createDidYouMeanMessage =
|
10 | exports.WARNING =
|
11 | exports.ValidationError =
|
12 | exports.ERROR =
|
13 | exports.DEPRECATION =
|
14 | void 0;
|
15 | function _chalk() {
|
16 | const data = _interopRequireDefault(require('chalk'));
|
17 | _chalk = function () {
|
18 | return data;
|
19 | };
|
20 | return data;
|
21 | }
|
22 | function _leven() {
|
23 | const data = _interopRequireDefault(require('leven'));
|
24 | _leven = function () {
|
25 | return data;
|
26 | };
|
27 | return data;
|
28 | }
|
29 | function _prettyFormat() {
|
30 | const data = require('pretty-format');
|
31 | _prettyFormat = function () {
|
32 | return data;
|
33 | };
|
34 | return data;
|
35 | }
|
36 | function _interopRequireDefault(obj) {
|
37 | return obj && obj.__esModule ? obj : {default: obj};
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | const BULLET = _chalk().default.bold('\u25cf');
|
47 | const DEPRECATION = `${BULLET} Deprecation Warning`;
|
48 | exports.DEPRECATION = DEPRECATION;
|
49 | const ERROR = `${BULLET} Validation Error`;
|
50 | exports.ERROR = ERROR;
|
51 | const WARNING = `${BULLET} Validation Warning`;
|
52 | exports.WARNING = WARNING;
|
53 | const format = value =>
|
54 | typeof value === 'function'
|
55 | ? value.toString()
|
56 | : (0, _prettyFormat().format)(value, {
|
57 | min: true
|
58 | });
|
59 | exports.format = format;
|
60 | const formatPrettyObject = value =>
|
61 | typeof value === 'function'
|
62 | ? value.toString()
|
63 | : typeof value === 'undefined'
|
64 | ? 'undefined'
|
65 | : JSON.stringify(value, null, 2).split('\n').join('\n ');
|
66 | exports.formatPrettyObject = formatPrettyObject;
|
67 | class ValidationError extends Error {
|
68 | name;
|
69 | message;
|
70 | constructor(name, message, comment) {
|
71 | super();
|
72 | comment = comment ? `\n\n${comment}` : '\n';
|
73 | this.name = '';
|
74 | this.message = _chalk().default.red(
|
75 | `${_chalk().default.bold(name)}:\n\n${message}${comment}`
|
76 | );
|
77 |
|
78 | Error.captureStackTrace(this, () => {});
|
79 | }
|
80 | }
|
81 | exports.ValidationError = ValidationError;
|
82 | const logValidationWarning = (name, message, comment) => {
|
83 | comment = comment ? `\n\n${comment}` : '\n';
|
84 | console.warn(
|
85 | _chalk().default.yellow(
|
86 | `${_chalk().default.bold(name)}:\n\n${message}${comment}`
|
87 | )
|
88 | );
|
89 | };
|
90 | exports.logValidationWarning = logValidationWarning;
|
91 | const createDidYouMeanMessage = (unrecognized, allowedOptions) => {
|
92 | const suggestion = allowedOptions.find(option => {
|
93 | const steps = (0, _leven().default)(option, unrecognized);
|
94 | return steps < 3;
|
95 | });
|
96 | return suggestion
|
97 | ? `Did you mean ${_chalk().default.bold(format(suggestion))}?`
|
98 | : '';
|
99 | };
|
100 | exports.createDidYouMeanMessage = createDidYouMeanMessage;
|