Replace custom "findSuggestion" function with "levenary" (#10924)

* Replace custom "findSuggestion" function with "levenary"

* Update
This commit is contained in:
Nicolò Ribaudo 2019-12-26 00:44:33 +01:00
parent db3c31a8af
commit 30f3b07ebf
6 changed files with 5 additions and 38 deletions

View File

@ -190,12 +190,6 @@ declare module "convert-source-map" {
};
}
declare module "js-levenshtein" {
declare module.exports: {
(string, string): number,
};
}
declare module "core-js-compat/data" {
declare type Target = "node" | "chrome" | "opera" | "edge" | "firefox" | "safari" | "ie" | "ios" | "android" | "electron" | "samsung";

View File

@ -63,7 +63,7 @@
"browserslist": "^4.6.0",
"core-js-compat": "^3.6.0",
"invariant": "^2.2.2",
"js-levenshtein": "^1.1.3",
"levenary": "^1.1.0",
"semver": "^5.5.0"
},
"peerDependencies": {

View File

@ -8,7 +8,7 @@ import moduleTransformations from "./module-transformations";
import { TopLevelOptions, ModulesOption, UseBuiltInsOption } from "./options";
import { defaultWebIncludes } from "./polyfills/corejs2/get-platform-specific-default";
import { isBrowsersQueryValid } from "./targets-parser";
import { findSuggestion } from "./utils";
import findSuggestion from "levenary";
import type {
BuiltInsOption,

View File

@ -3,12 +3,8 @@
import browserslist from "browserslist";
import invariant from "invariant";
import semver from "semver";
import {
semverify,
isUnreleasedVersion,
getLowestUnreleased,
findSuggestion,
} from "./utils";
import findSuggestion from "levenary";
import { semverify, isUnreleasedVersion, getLowestUnreleased } from "./utils";
import browserModulesData from "../data/built-in-modules.json";
import { TargetNames } from "./options";
import type { Targets } from "./types";

View File

@ -4,7 +4,6 @@ import * as t from "@babel/types";
import type { NodePath } from "@babel/traverse";
import invariant from "invariant";
import semver from "semver";
import levenshtein from "js-levenshtein";
import { addSideEffect } from "@babel/helper-module-imports";
import unreleasedLabels from "../data/unreleased-labels";
import { semverMin } from "./targets-parser";
@ -53,18 +52,6 @@ export function intersection<T>(
return result;
}
export function findSuggestion(options: string[], option: string): string {
let levenshteinValue = Infinity;
return options.reduce((suggestion, validOption) => {
const value = levenshtein(validOption, option);
if (value < levenshteinValue) {
levenshteinValue = value;
return validOption;
}
return suggestion;
}, "");
}
export function prettifyVersion(version: string) {
if (typeof version !== "string") {
return version;

View File

@ -2,7 +2,7 @@
const utils = require("../lib/utils");
const { prettifyTargets, prettifyVersion, semverify, findSuggestion } = utils;
const { prettifyTargets, prettifyVersion, semverify } = utils;
describe("utils", () => {
describe("semverify", () => {
@ -50,14 +50,4 @@ describe("utils", () => {
});
});
});
describe("findSuggestion", () => {
it("returns", () => {
const options = ["one", "two", "three"];
expect(findSuggestion(options, "onr")).toEqual("one");
expect(findSuggestion(options, "tree")).toEqual("three");
expect(findSuggestion(options, "")).toEqual("one");
expect(findSuggestion(options, "xxx")).toEqual("one");
});
});
});