UNPKG

@salesforce/core

Version:

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

40 lines 1.74 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 2026, Salesforce, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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