UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

31 lines 1.37 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.findSuggestion = void 0; /* * Copyright (c) 2023, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ const fast_levenshtein_1 = __importDefault(require("fast-levenshtein")); /** * From the haystack, will find the closest value to the needle * * @param needle - what the user provided - find results similar to this * @param haystack - possible results to search against */ const findSuggestion = (needle, haystack) => { // we'll use this array to keep track of which piece of hay is the closest to the users entered value. // keys closer to the index 0 will be a closer guess than keys indexed further from 0 // an entry at 0 would be a direct match, an entry at 1 would be a single character off, etc. const index = []; haystack.map((hay) => { index[fast_levenshtein_1.default.get(needle, hay)] = hay; }); return index.find((item) => item !== undefined) ?? ''; }; exports.findSuggestion = findSuggestion; //# sourceMappingURL=findSuggestion.js.map