source: imaps-frontend/node_modules/@babel/helper-validator-option/lib/validator.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • 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;
7var _findSuggestion = require("./find-suggestion.js");
8class OptionValidator {
9 constructor(descriptor) {
10 this.descriptor = descriptor;
11 }
12 validateTopLevelOptions(options, TopLevelOptionShape) {
13 const validOptionNames = Object.keys(TopLevelOptionShape);
14 for (const option of Object.keys(options)) {
15 if (!validOptionNames.includes(option)) {
16 throw new Error(this.formatMessage(`'${option}' is not a valid top-level option.
17- Did you mean '${(0, _findSuggestion.findSuggestion)(option, validOptionNames)}'?`));
18 }
19 }
20 }
21 validateBooleanOption(name, value, defaultValue) {
22 if (value === undefined) {
23 return defaultValue;
24 } else {
25 this.invariant(typeof value === "boolean", `'${name}' option must be a boolean.`);
26 }
27 return value;
28 }
29 validateStringOption(name, value, defaultValue) {
30 if (value === undefined) {
31 return defaultValue;
32 } else {
33 this.invariant(typeof value === "string", `'${name}' option must be a string.`);
34 }
35 return value;
36 }
37 invariant(condition, message) {
38 if (!condition) {
39 throw new Error(this.formatMessage(message));
40 }
41 }
42 formatMessage(message) {
43 return `${this.descriptor}: ${message}`;
44 }
45}
46exports.OptionValidator = OptionValidator;
47
48//# sourceMappingURL=validator.js.map
Note: See TracBrowser for help on using the repository browser.