@acusti/matchmaking
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -6,3 +6,4 @@ const FIRST_NUMBER = '0'.charCodeAt(0); | ||
const MAX_DISTANCE = 15; | ||
const MAX_INEXACT_SCORE = 0.999999; | ||
const MAX_INEXACT_SCORE = 0.99999; | ||
const MAX_PARTIAL_EXACT_SCORE = 0.999999; | ||
export const getMatchScore = (strA, strB, isSanitized) => { | ||
@@ -13,2 +14,3 @@ if (!isSanitized) { | ||
} | ||
// Exact match scores 1 | ||
if (strA === strB) | ||
@@ -19,2 +21,6 @@ return 1; | ||
const shortestLength = Math.min(strALength, strBLength); | ||
// Exact partial match is next best score to exact match | ||
if (strA.slice(0, shortestLength) === strB.slice(0, shortestLength)) { | ||
return MAX_PARTIAL_EXACT_SCORE; | ||
} | ||
// To proportionally weight consecutive exact matches, increase bonus relative to total length | ||
@@ -51,4 +57,5 @@ const bonusMultiplier = Math.min(0.25, 3 / shortestLength); | ||
// If score came out at 0 or less, give it best possible score for an inexact match | ||
if (score <= 0) | ||
if (score <= 0) { | ||
return MAX_INEXACT_SCORE; | ||
} | ||
score = (worstPossibleScore - score) / worstPossibleScore; | ||
@@ -55,0 +62,0 @@ // Don’t allow an inexact match to get a score of 1 (reserved for an exact match) |
{ | ||
"name": "@acusti/matchmaking", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"type": "module", | ||
"exports": "./dist/index.js", | ||
"module": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"files": [ | ||
@@ -9,0 +12,0 @@ "dist" |
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
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
8321
92