source: trip-planner-front/node_modules/@babel/helper-validator-option/lib/validator.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.OptionValidator = void 0;
7
8var _findSuggestion = require("./find-suggestion");
9
10class OptionValidator {
11 constructor(descriptor) {
12 this.descriptor = descriptor;
13 }
14
15 validateTopLevelOptions(options, TopLevelOptionShape) {
16 const validOptionNames = Object.keys(TopLevelOptionShape);
17
18 for (const option of Object.keys(options)) {
19 if (!validOptionNames.includes(option)) {
20 throw new Error(this.formatMessage(`'${option}' is not a valid top-level option.
21- Did you mean '${(0, _findSuggestion.findSuggestion)(option, validOptionNames)}'?`));
22 }
23 }
24 }
25
26 validateBooleanOption(name, value, defaultValue) {
27 if (value === undefined) {
28 return defaultValue;
29 } else {
30 this.invariant(typeof value === "boolean", `'${name}' option must be a boolean.`);
31 }
32
33 return value;
34 }
35
36 validateStringOption(name, value, defaultValue) {
37 if (value === undefined) {
38 return defaultValue;
39 } else {
40 this.invariant(typeof value === "string", `'${name}' option must be a string.`);
41 }
42
43 return value;
44 }
45
46 invariant(condition, message) {
47 if (!condition) {
48 throw new Error(this.formatMessage(message));
49 }
50 }
51
52 formatMessage(message) {
53 return `${this.descriptor}: ${message}`;
54 }
55
56}
57
58exports.OptionValidator = OptionValidator;
Note: See TracBrowser for help on using the repository browser.