Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@filerobot/explorer / lib / utils / getClosestStr.js
Size: Mime:
import levenshtein from 'js-levenshtein';
export default function getClosestStr(str, options) {
  if (str) {
    var closestValue = (options || []).filter(function (option) {
      return option && typeof option === 'string';
    }).reduce(function (acum, currentOption) {
      var value = currentOption || '';
      var distance = levenshtein((str || '').toLowerCase(), value.toLowerCase());
      if (!acum || distance < (acum === null || acum === void 0 ? void 0 : acum.distance)) {
        return {
          value: value,
          distance: distance
        };
      }
      return acum;
    }, null);
    if (closestValue !== null && closestValue !== void 0 && closestValue.value) {
      return closestValue.value;
    }
  }
  return null;
}