Skip to content

Commit bc282d1

Browse files
committed
refactor: ⚡️ implement @CodeRabbit suggestions
1 parent e4d08ca commit bc282d1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/services/author-parser.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { AuthorParserOptions } from 'types';
22

33
export class AuthorParser {
4-
private readonly AUTHOR_SEPARATORS = /,\s*and\s*|\s+and\s+|,\s*/;
4+
/** Matches common separators between author names: comma-and, and, or comma */
5+
private readonly AUTHOR_SEPARATORS = /(?:,\s*and\s*)|(?:\s+and\s+)|(?:,\s*)/;
6+
/** Matches common English titles at the start of a name */
57
private readonly TITLES = /^(dr|prof|mr|mrs|ms|miss|sir|lady)\.\s+/i;
68

79
constructor(private options: AuthorParserOptions = {}) {
@@ -24,7 +26,12 @@ export class AuthorParser {
2426
return authorString
2527
.split(this.AUTHOR_SEPARATORS)
2628
.map(author => this.processAuthor(author))
27-
.filter(Boolean);
29+
.filter(author => {
30+
if (!author) {
31+
return false;
32+
}
33+
return true;
34+
});
2835
}
2936

3037
/**

0 commit comments

Comments
 (0)