{
  "version": 3,
  "sources": ["../../../src/validation-errors/enum.js"],
  "sourcesContent": ["import chalk from 'chalk';\nimport leven from 'leven';\nimport pointer from 'jsonpointer';\nimport BaseValidationError from './base';\n\nexport default class EnumValidationError extends BaseValidationError {\n  print() {\n    const {\n      message,\n      params: { allowedValues },\n    } = this.options;\n    const bestMatch = this.findBestMatch();\n\n    const output = [\n      chalk`{red {bold ENUM} ${message}}`,\n      chalk`{red (${allowedValues.join(', ')})}\\n`,\n    ];\n\n    return output.concat(\n      this.getCodeFrame(\n        bestMatch !== null\n          ? chalk`\uD83D\uDC48\uD83C\uDFFD  Did you mean {magentaBright ${bestMatch}} here?`\n          : chalk`\uD83D\uDC48\uD83C\uDFFD  Unexpected value, should be equal to one of the allowed values`\n      )\n    );\n  }\n\n  getError() {\n    const { message, params } = this.options;\n    const bestMatch = this.findBestMatch();\n    const allowedValues = params.allowedValues.join(', ');\n\n    const output = {\n      ...this.getLocation(),\n      error: `${this.getDecoratedPath()} ${message}: ${allowedValues}`,\n      path: this.instancePath,\n    };\n\n    if (bestMatch !== null) {\n      output.suggestion = `Did you mean ${bestMatch}?`;\n    }\n\n    return output;\n  }\n\n  findBestMatch() {\n    const {\n      params: { allowedValues },\n    } = this.options;\n\n    const currentValue =\n      this.instancePath === ''\n        ? this.data\n        : pointer.get(this.data, this.instancePath);\n\n    if (!currentValue) {\n      return null;\n    }\n\n    const bestMatch = allowedValues\n      .map(value => ({\n        value,\n        weight: leven(value, currentValue.toString()),\n      }))\n      .sort((x, y) =>\n        x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0\n      )[0];\n\n    return allowedValues.length === 1 ||\n      bestMatch.weight < bestMatch.value.length\n      ? bestMatch.value\n      : null;\n  }\n}\n"],
  "mappings": ";AAAA,OAAO,WAAW;AAClB,OAAO,WAAW;AAClB,OAAO,aAAa;AACpB,OAAO,yBAAyB;AAEhC,IAAqB,sBAArB,cAAiD,oBAAoB;AAAA,EACnE,QAAQ;AACN,UAAM;AAAA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