@acusti/matchmaking
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,2 +0,6 @@ | ||
export declare const getMatchScore: (strA: string, strB: string, isSanitized?: boolean | undefined) => number; | ||
export declare const getMatchScore: ( | ||
strA: string, | ||
strB: string, | ||
isSanitized?: boolean | undefined, | ||
) => number; | ||
declare type Payload = { | ||
@@ -3,0 +7,0 @@ items: Array<string>; |
@@ -14,4 +14,3 @@ const FIRST_NUMBER = '0'.charCodeAt(0); | ||
// Exact match scores 1 | ||
if (strA === strB) | ||
return 1; | ||
if (strA === strB) return 1; | ||
const strALength = strA.length; | ||
@@ -35,5 +34,7 @@ const strBLength = strB.length; | ||
// If comparing a number to a letter, use minimum distance ('z' should be considered same distance from '3' as 'a') | ||
if (strACharCode >= FIRST_NUMBER && | ||
if ( | ||
strACharCode >= FIRST_NUMBER && | ||
strACharCode <= LAST_NUMBER && | ||
strBCharCode > FIRST_LETTER) { | ||
strBCharCode > FIRST_LETTER | ||
) { | ||
distance = LAST_NUMBER + 1 - strACharCode; | ||
@@ -48,4 +49,3 @@ } | ||
score = exactMatchBonus; | ||
} | ||
else { | ||
} else { | ||
// Non-continuous exact match gets the minimum bonus | ||
@@ -66,4 +66,3 @@ score -= 1; | ||
text = text.trim().toUpperCase(); | ||
if (!text || !items.length) | ||
return items; | ||
if (!text || !items.length) return items; | ||
const initialValues = [[], []]; | ||
@@ -75,4 +74,3 @@ const [sortedItems] = items.reduce(([sorted, scores], item) => { | ||
index = 0; | ||
} | ||
else if (itemScore > scores[scores.length - 1]) { | ||
} else if (itemScore > scores[scores.length - 1]) { | ||
const insertIndex = scores.findIndex((score) => score < itemScore); | ||
@@ -90,2 +88,2 @@ if (insertIndex !== -1) { | ||
export const getBestMatch = (payload) => sortByBestMatch(payload)[0]; | ||
//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@acusti/matchmaking", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"type": "module", | ||
@@ -10,3 +10,4 @@ "sideEffects": false, | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"src" | ||
], | ||
@@ -17,3 +18,3 @@ "repository": { | ||
}, | ||
"author": "andrew patton <andrew@acusti.ca> (http://acusti.ca)", | ||
"author": "andrew patton <andrew@acusti.ca> (https://www.acusti.ca)", | ||
"license": "Unlicense", | ||
@@ -25,4 +26,4 @@ "bugs": { | ||
"devDependencies": { | ||
"typescript": "^4.2.3" | ||
"typescript": "^4.4.3" | ||
} | ||
} |
# @acusti/matchmaking | ||
![latest version](https://img.shields.io/npm/v/@acusti/matchmaking?style=for-the-badge) | ||
![dependencies status](https://img.shields.io/david/acusti/uikit?path=packages%2Fmatchmaking&style=for-the-badge) | ||
![bundle size](https://img.shields.io/bundlephobia/minzip/@acusti/matchmaking?style=for-the-badge) | ||
![downloads per month](https://img.shields.io/npm/dm/@acusti/matchmaking?style=for-the-badge) | ||
[![latest version](https://img.shields.io/npm/v/@acusti/matchmaking?style=for-the-badge)](https://www.npmjs.com/package/@acusti/matchmaking) | ||
[![dependencies status](https://img.shields.io/david/acusti/uikit?path=packages%2Fmatchmaking&style=for-the-badge)](https://david-dm.org/acusti/uikit?path=packages%2Fmatchmaking) | ||
[![bundle size](https://img.shields.io/bundlephobia/minzip/@acusti/matchmaking?style=for-the-badge)](https://bundlephobia.com/package/@acusti/matchmaking) | ||
[![downloads per month](https://img.shields.io/npm/dm/@acusti/matchmaking?style=for-the-badge)](https://www.npmjs.com/package/@acusti/matchmaking) | ||
Utilities for simple approximate string matching (i.e. fuzzy searches) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16378
8
300
1