diff options
Diffstat (limited to 'node_modules/@babel/helper-validator-option')
6 files changed, 188 insertions, 0 deletions
diff --git a/node_modules/@babel/helper-validator-option/LICENSE b/node_modules/@babel/helper-validator-option/LICENSE new file mode 100644 index 0000000..f31575e --- /dev/null +++ b/node_modules/@babel/helper-validator-option/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2014-present Sebastian McKenzie and other contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/@babel/helper-validator-option/README.md b/node_modules/@babel/helper-validator-option/README.md new file mode 100644 index 0000000..94ab428 --- /dev/null +++ b/node_modules/@babel/helper-validator-option/README.md @@ -0,0 +1,19 @@ +# @babel/helper-validator-option + +> Validate plugin/preset options + +See our website [@babel/helper-validator-option](https://babeljs.io/docs/en/babel-helper-validator-option) for more information. + +## Install + +Using npm: + +```sh +npm install --save @babel/helper-validator-option +``` + +or using yarn: + +```sh +yarn add @babel/helper-validator-option +``` diff --git a/node_modules/@babel/helper-validator-option/lib/find-suggestion.js b/node_modules/@babel/helper-validator-option/lib/find-suggestion.js new file mode 100644 index 0000000..019ea93 --- /dev/null +++ b/node_modules/@babel/helper-validator-option/lib/find-suggestion.js @@ -0,0 +1,45 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { +  value: true +}); +exports.findSuggestion = findSuggestion; +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))]; +}
\ No newline at end of file diff --git a/node_modules/@babel/helper-validator-option/lib/index.js b/node_modules/@babel/helper-validator-option/lib/index.js new file mode 100644 index 0000000..8afe861 --- /dev/null +++ b/node_modules/@babel/helper-validator-option/lib/index.js @@ -0,0 +1,21 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { +  value: true +}); +Object.defineProperty(exports, "OptionValidator", { +  enumerable: true, +  get: function () { +    return _validator.OptionValidator; +  } +}); +Object.defineProperty(exports, "findSuggestion", { +  enumerable: true, +  get: function () { +    return _findSuggestion.findSuggestion; +  } +}); + +var _validator = require("./validator"); + +var _findSuggestion = require("./find-suggestion");
\ No newline at end of file diff --git a/node_modules/@babel/helper-validator-option/lib/validator.js b/node_modules/@babel/helper-validator-option/lib/validator.js new file mode 100644 index 0000000..5b4bad1 --- /dev/null +++ b/node_modules/@babel/helper-validator-option/lib/validator.js @@ -0,0 +1,58 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { +  value: true +}); +exports.OptionValidator = void 0; + +var _findSuggestion = require("./find-suggestion"); + +class OptionValidator { +  constructor(descriptor) { +    this.descriptor = descriptor; +  } + +  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 '${(0, _findSuggestion.findSuggestion)(option, validOptionNames)}'?`)); +      } +    } +  } + +  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}`; +  } + +} + +exports.OptionValidator = OptionValidator;
\ No newline at end of file diff --git a/node_modules/@babel/helper-validator-option/package.json b/node_modules/@babel/helper-validator-option/package.json new file mode 100644 index 0000000..1fe2da8 --- /dev/null +++ b/node_modules/@babel/helper-validator-option/package.json @@ -0,0 +1,23 @@ +{ +  "name": "@babel/helper-validator-option", +  "version": "7.16.7", +  "description": "Validate plugin/preset options", +  "repository": { +    "type": "git", +    "url": "https://github.com/babel/babel.git", +    "directory": "packages/babel-helper-validator-option" +  }, +  "license": "MIT", +  "publishConfig": { +    "access": "public" +  }, +  "main": "./lib/index.js", +  "exports": { +    ".": "./lib/index.js", +    "./package.json": "./package.json" +  }, +  "engines": { +    "node": ">=6.9.0" +  }, +  "author": "The Babel Team (https://babel.dev/team)" +}
\ No newline at end of file  | 
