Skip to content

Commit

Permalink
fix: nth formatting for values above 20 (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Aug 15, 2024
1 parent 27c2372 commit 1c0ecf1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/composables/strings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export function nth(n: number) {
if (n === 1)
return '1st'
if (n === 2)
return '2nd'
if (n === 3)
return '3rd'
const nString = `${n}`
if (nString.endsWith('1') && n !== 11)
return `${nString}st`
if (nString.endsWith('2') && n !== 12)
return `${nString}nd`
if (nString.endsWith('3') && n !== 13)
return `${nString}rd`
return `${n}th`
}

Expand Down

0 comments on commit 1c0ecf1

Please sign in to comment.