@babel/helper-validator-option
Advanced tools
Comparing version 7.22.5 to 8.0.0-alpha.0
@@ -1,7 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.findSuggestion = findSuggestion; | ||
const { | ||
@@ -34,3 +28,3 @@ min | ||
} | ||
function findSuggestion(str, arr) { | ||
export function findSuggestion(str, arr) { | ||
const distances = arr.map(el => levenshtein(el, str)); | ||
@@ -37,0 +31,0 @@ return arr[distances.indexOf(min(...distances))]; |
@@ -1,21 +0,73 @@ | ||
"use strict"; | ||
const { | ||
min | ||
} = Math; | ||
function levenshtein(a, b) { | ||
let t = [], | ||
u = [], | ||
i, | ||
j; | ||
const m = a.length, | ||
n = b.length; | ||
if (!m) { | ||
return n; | ||
} | ||
if (!n) { | ||
return m; | ||
} | ||
for (j = 0; j <= n; j++) { | ||
t[j] = j; | ||
} | ||
for (i = 1; i <= m; i++) { | ||
for (u = [i], j = 1; j <= n; j++) { | ||
u[j] = a[i - 1] === b[j - 1] ? t[j - 1] : min(t[j - 1], t[j], u[j - 1]) + 1; | ||
} | ||
t = u; | ||
} | ||
return u[n]; | ||
} | ||
function findSuggestion(str, arr) { | ||
const distances = arr.map(el => levenshtein(el, str)); | ||
return arr[distances.indexOf(min(...distances))]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "OptionValidator", { | ||
enumerable: true, | ||
get: function () { | ||
return _validator.OptionValidator; | ||
class OptionValidator { | ||
constructor(descriptor) { | ||
this.descriptor = descriptor; | ||
} | ||
}); | ||
Object.defineProperty(exports, "findSuggestion", { | ||
enumerable: true, | ||
get: function () { | ||
return _findSuggestion.findSuggestion; | ||
validateTopLevelOptions(options, TopLevelOptionShape) { | ||
const validOptionNames = Object.keys(TopLevelOptionShape); | ||
for (const option of Object.keys(options)) { | ||
if (!validOptionNames.includes(option)) { | ||
throw new Error(this.formatMessage(`'${option}' is not a valid top-level option. | ||
- Did you mean '${findSuggestion(option, validOptionNames)}'?`)); | ||
} | ||
} | ||
} | ||
}); | ||
var _validator = require("./validator"); | ||
var _findSuggestion = require("./find-suggestion"); | ||
validateBooleanOption(name, value, defaultValue) { | ||
if (value === undefined) { | ||
return defaultValue; | ||
} else { | ||
this.invariant(typeof value === "boolean", `'${name}' option must be a boolean.`); | ||
} | ||
return value; | ||
} | ||
validateStringOption(name, value, defaultValue) { | ||
if (value === undefined) { | ||
return defaultValue; | ||
} else { | ||
this.invariant(typeof value === "string", `'${name}' option must be a string.`); | ||
} | ||
return value; | ||
} | ||
invariant(condition, message) { | ||
if (!condition) { | ||
throw new Error(this.formatMessage(message)); | ||
} | ||
} | ||
formatMessage(message) { | ||
return `${this.descriptor}: ${message}`; | ||
} | ||
} | ||
export { OptionValidator, findSuggestion }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.OptionValidator = void 0; | ||
var _findSuggestion = require("./find-suggestion"); | ||
class OptionValidator { | ||
import { findSuggestion } from "./find-suggestion.js"; | ||
export class OptionValidator { | ||
constructor(descriptor) { | ||
@@ -17,3 +11,3 @@ this.descriptor = descriptor; | ||
throw new Error(this.formatMessage(`'${option}' is not a valid top-level option. | ||
- Did you mean '${(0, _findSuggestion.findSuggestion)(option, validOptionNames)}'?`)); | ||
- Did you mean '${findSuggestion(option, validOptionNames)}'?`)); | ||
} | ||
@@ -47,4 +41,3 @@ } | ||
} | ||
exports.OptionValidator = OptionValidator; | ||
//# sourceMappingURL=validator.js.map |
{ | ||
"name": "@babel/helper-validator-option", | ||
"version": "7.22.5", | ||
"version": "8.0.0-alpha.0", | ||
"description": "Validate plugin/preset options", | ||
@@ -20,6 +20,6 @@ "repository": { | ||
"engines": { | ||
"node": ">=6.9.0" | ||
"node": "^16.20.0 || ^18.16.0 || >=20.0.0" | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"type": "commonjs" | ||
"type": "module" | ||
} |
@@ -5,3 +5,3 @@ # @babel/helper-validator-option | ||
See our website [@babel/helper-validator-option](https://babeljs.io/docs/en/babel-helper-validator-option) for more information. | ||
See our website [@babel/helper-validator-option](https://babeljs.io/docs/babel-helper-validator-option) for more information. | ||
@@ -8,0 +8,0 @@ ## Install |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19151
143
Yes
2