mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-27 06:09:38 +00:00
Add levenshteinSimilarity function to utils
This commit is contained in:
parent
d01a7cb756
commit
387e58a714
1 changed files with 8 additions and 0 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue