diff --git a/server/objects/entities/Author.js b/server/objects/entities/Author.js index 56f9233d..463c9cac 100644 --- a/server/objects/entities/Author.js +++ b/server/objects/entities/Author.js @@ -1,5 +1,6 @@ const Logger = require('../../Logger') const { getId } = require('../../utils/index') +const { checkNamesAreEqual } = require('../../utils/parsers/parseNameString') class Author { constructor(author) { @@ -86,7 +87,7 @@ class Author { Logger.error(`[Author] Author name is null (${this.id})`) return false } - return this.name.toLowerCase() == name.toLowerCase().trim() + return checkNamesAreEqual(this.name, name) } } module.exports = Author \ No newline at end of file diff --git a/server/utils/parsers/parseNameString.js b/server/utils/parsers/parseNameString.js index 068470a1..d2d80d2d 100644 --- a/server/utils/parsers/parseNameString.js +++ b/server/utils/parsers/parseNameString.js @@ -91,4 +91,13 @@ module.exports.parse = (nameString) => { nameLF: lastFirst, // String of comma separated last, first names: namesArray // Array of first last } +} + +module.exports.checkNamesAreEqual = (name1, name2) => { + if (!name1 || !name2) return false + + // e.g. John H. Smith will be equal to John H Smith + name1 = String(name1).toLowerCase().trim().replace(/\./g, '') + name2 = String(name2).toLowerCase().trim().replace(/\./g, '') + return name1 === name2 } \ No newline at end of file