UNPKG

ts-mysql-analyzer

Version:

A MySQL query analyzer.

34 lines 986 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const leven_1 = __importDefault(require("leven")); function autocorrect(inputWord, words) { let bestWord = null; let min = null; for (let i = 0; i < words.length; i++) { const word = words[i]; const distance = leven_1.default(inputWord, word); if (distance === 0) { return word; } else if (!min || distance < min) { min = distance; bestWord = word; } } return bestWord; } function getCorrection(word, words) { const correction = autocorrect(word, words); if (!correction) { return ''; } if (correction === word) { return ''; } return correction; } exports.getCorrection = getCorrection; //# sourceMappingURL=autocorrect.js.map