Add stripRedudantSpaces

This commit is contained in:
mikiher 2023-11-08 16:21:20 +00:00
parent 819c524f51
commit 49e4515785

View File

@ -439,6 +439,8 @@ function replaceAccentedChars(str) {
function cleanTitleForCompares(title) {
if (!title) return ''
title = stripRedundantSpaces(title)
// Remove subtitle if there (i.e. "Cool Book: Coolest Ever" becomes "Cool Book")
let stripped = stripSubtitle(title)
@ -452,6 +454,8 @@ function cleanTitleForCompares(title) {
function cleanAuthorForCompares(author) {
if (!author) return ''
author = stripRedundantSpaces(author)
let cleanAuthor = replaceAccentedChars(author).toLowerCase()
// separate initials
cleanAuthor = cleanAuthor.replace(/([a-z])\.([a-z])/g, '$1. $2')
@ -459,3 +463,7 @@ function cleanAuthorForCompares(author) {
cleanAuthor = cleanAuthor.replace(/(?<=\w\w)(\s+[a-z]\.?)+(?=\s+\w\w)/g, '')
return cleanAuthor
}
function stripRedundantSpaces(str) {
return str.replace(/\s+/g, ' ').trim()
}