replace js-levenshtein with sift-string

master
Brad Cornes 2020-06-18 14:53:20 +01:00
parent 6cbd49a74a
commit 983cfe5ac7
3 changed files with 9 additions and 18 deletions

18
package-lock.json generated
View File

@ -1027,12 +1027,6 @@
"@types/istanbul-lib-report": "*" "@types/istanbul-lib-report": "*"
} }
}, },
"@types/js-levenshtein": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@types/js-levenshtein/-/js-levenshtein-1.1.0.tgz",
"integrity": "sha512-14t0v1ICYRtRVcHASzes0v/O+TIeASb8aD55cWF1PidtInhFWSXcmhzhHqGjUWf9SUq1w70cvd1cWKUULubAfQ==",
"dev": true
},
"@types/mocha": { "@types/mocha": {
"version": "5.2.1", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.1.tgz", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.1.tgz",
@ -4603,12 +4597,6 @@
} }
} }
}, },
"js-levenshtein": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz",
"integrity": "sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==",
"dev": true
},
"js-tokens": { "js-tokens": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@ -6102,6 +6090,12 @@
"dev": true, "dev": true,
"optional": true "optional": true
}, },
"sift-string": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/sift-string/-/sift-string-0.0.2.tgz",
"integrity": "sha1-G7ArEhslu4sHRwQr+afh2s+PuJw=",
"dev": true
},
"signal-exit": { "signal-exit": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",

View File

@ -156,7 +156,6 @@
}, },
"devDependencies": { "devDependencies": {
"@ctrl/tinycolor": "^3.1.0", "@ctrl/tinycolor": "^3.1.0",
"@types/js-levenshtein": "^1.1.0",
"@types/mocha": "^5.2.0", "@types/mocha": "^5.2.0",
"@types/moo": "^0.5.3", "@types/moo": "^0.5.3",
"@types/node": "^13.9.3", "@types/node": "^13.9.3",
@ -175,7 +174,6 @@
"globrex": "^0.1.2", "globrex": "^0.1.2",
"import-from": "^3.0.0", "import-from": "^3.0.0",
"jest": "^25.5.4", "jest": "^25.5.4",
"js-levenshtein": "^1.1.6",
"line-column": "^1.0.2", "line-column": "^1.0.2",
"mitt": "^1.2.0", "mitt": "^1.2.0",
"mkdirp": "^1.0.3", "mkdirp": "^1.0.3",
@ -186,6 +184,7 @@
"resolve-from": "^5.0.0", "resolve-from": "^5.0.0",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"semver": "^7.3.2", "semver": "^7.3.2",
"sift-string": "0.0.2",
"stack-trace": "0.0.10", "stack-trace": "0.0.10",
"terser": "^4.6.12", "terser": "^4.6.12",
"tiny-invariant": "^1.1.0", "tiny-invariant": "^1.1.0",

View File

@ -1,7 +1,5 @@
import levenshtein from 'js-levenshtein' import sift from 'sift-string'
export function closest(input: string, options: string[]): string | undefined { export function closest(input: string, options: string[]): string | undefined {
return options.sort( return options.concat([]).sort((a, b) => sift(input, a) - sift(input, b))[0]
(a, b) => levenshtein(input, a) - levenshtein(input, b)
)[0]
} }