Skip to content

Commit b2f1b7c

Browse files
committed
refactor: use Intl.ListFormat for joining the authors
1 parent e58fda7 commit b2f1b7c

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

app/utils/blog.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1+
const joiner = new Intl.ListFormat('en-US', {
2+
style: 'long',
3+
type: 'conjunction',
4+
})
5+
16
export function formatAuthors(authors: Array<string>) {
27
if (!authors.length) {
38
return 'TanStack'
49
}
510

6-
if (authors.length === 1) {
7-
return authors[0]
8-
}
9-
10-
if (authors.length === 2) {
11-
return authors.join(' and ')
12-
}
13-
14-
return authors.slice(0, -1).join(', ') + ', and ' + authors.slice(-1)
11+
return joiner.format(authors)
1512
}

0 commit comments

Comments
 (0)