mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-26 13:51:16 +02:00
Add levenshteinSimilarity function to utils
This commit is contained in:
parent
d01a7cb756
commit
387e58a714
@ -34,6 +34,14 @@ const levenshteinDistance = (str1, str2, caseSensitive = false) => {
|
||||
}
|
||||
module.exports.levenshteinDistance = levenshteinDistance
|
||||
|
||||
const levenshteinSimilarity = (str1, str2, caseSensitive = false) => {
|
||||
const distance = levenshteinDistance(str1, str2, caseSensitive)
|
||||
const maxLength = Math.max(str1.length, str2.length)
|
||||
if (maxLength === 0) return 1
|
||||
return 1 - distance / maxLength
|
||||
}
|
||||
module.exports.levenshteinSimilarity = levenshteinSimilarity
|
||||
|
||||
module.exports.isObject = (val) => {
|
||||
return val !== null && typeof val === 'object'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user