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