From 1c0ecf195bb18a41a97367ee03d916331806cfb5 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Thu, 15 Aug 2024 15:05:37 +0200 Subject: [PATCH] fix: `nth` formatting for values above 20 (#83) --- app/composables/strings.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/composables/strings.ts b/app/composables/strings.ts index 8103486..a0f3828 100644 --- a/app/composables/strings.ts +++ b/app/composables/strings.ts @@ -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` }