Replace custom "findSuggestion" function with "levenary" (#10924)
* Replace custom "findSuggestion" function with "levenary" * Update
This commit is contained in:
parent
db3c31a8af
commit
30f3b07ebf
@ -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 module "core-js-compat/data" {
|
||||||
declare type Target = "node" | "chrome" | "opera" | "edge" | "firefox" | "safari" | "ie" | "ios" | "android" | "electron" | "samsung";
|
declare type Target = "node" | "chrome" | "opera" | "edge" | "firefox" | "safari" | "ie" | "ios" | "android" | "electron" | "samsung";
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,7 @@
|
|||||||
"browserslist": "^4.6.0",
|
"browserslist": "^4.6.0",
|
||||||
"core-js-compat": "^3.6.0",
|
"core-js-compat": "^3.6.0",
|
||||||
"invariant": "^2.2.2",
|
"invariant": "^2.2.2",
|
||||||
"js-levenshtein": "^1.1.3",
|
"levenary": "^1.1.0",
|
||||||
"semver": "^5.5.0"
|
"semver": "^5.5.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import moduleTransformations from "./module-transformations";
|
|||||||
import { TopLevelOptions, ModulesOption, UseBuiltInsOption } from "./options";
|
import { TopLevelOptions, ModulesOption, UseBuiltInsOption } from "./options";
|
||||||
import { defaultWebIncludes } from "./polyfills/corejs2/get-platform-specific-default";
|
import { defaultWebIncludes } from "./polyfills/corejs2/get-platform-specific-default";
|
||||||
import { isBrowsersQueryValid } from "./targets-parser";
|
import { isBrowsersQueryValid } from "./targets-parser";
|
||||||
import { findSuggestion } from "./utils";
|
import findSuggestion from "levenary";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
BuiltInsOption,
|
BuiltInsOption,
|
||||||
|
|||||||
@ -3,12 +3,8 @@
|
|||||||
import browserslist from "browserslist";
|
import browserslist from "browserslist";
|
||||||
import invariant from "invariant";
|
import invariant from "invariant";
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
import {
|
import findSuggestion from "levenary";
|
||||||
semverify,
|
import { semverify, isUnreleasedVersion, getLowestUnreleased } from "./utils";
|
||||||
isUnreleasedVersion,
|
|
||||||
getLowestUnreleased,
|
|
||||||
findSuggestion,
|
|
||||||
} from "./utils";
|
|
||||||
import browserModulesData from "../data/built-in-modules.json";
|
import browserModulesData from "../data/built-in-modules.json";
|
||||||
import { TargetNames } from "./options";
|
import { TargetNames } from "./options";
|
||||||
import type { Targets } from "./types";
|
import type { Targets } from "./types";
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import * as t from "@babel/types";
|
|||||||
import type { NodePath } from "@babel/traverse";
|
import type { NodePath } from "@babel/traverse";
|
||||||
import invariant from "invariant";
|
import invariant from "invariant";
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
import levenshtein from "js-levenshtein";
|
|
||||||
import { addSideEffect } from "@babel/helper-module-imports";
|
import { addSideEffect } from "@babel/helper-module-imports";
|
||||||
import unreleasedLabels from "../data/unreleased-labels";
|
import unreleasedLabels from "../data/unreleased-labels";
|
||||||
import { semverMin } from "./targets-parser";
|
import { semverMin } from "./targets-parser";
|
||||||
@ -53,18 +52,6 @@ export function intersection<T>(
|
|||||||
return result;
|
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) {
|
export function prettifyVersion(version: string) {
|
||||||
if (typeof version !== "string") {
|
if (typeof version !== "string") {
|
||||||
return version;
|
return version;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const utils = require("../lib/utils");
|
const utils = require("../lib/utils");
|
||||||
|
|
||||||
const { prettifyTargets, prettifyVersion, semverify, findSuggestion } = utils;
|
const { prettifyTargets, prettifyVersion, semverify } = utils;
|
||||||
|
|
||||||
describe("utils", () => {
|
describe("utils", () => {
|
||||||
describe("semverify", () => {
|
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");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user