formatDate fixed
Some checks failed
Build / Build NPM Project (push) Successful in 1m12s
Build / Tag Version (push) Successful in 16s
Build / Publish Documentation (push) Failing after 16s

This commit is contained in:
2025-08-01 11:06:07 -04:00
parent c5270fbd7e
commit 31998c01d6
4 changed files with 89 additions and 79 deletions

View File

@@ -49,12 +49,16 @@ export function fracToDec(frac: string) {
return whole + (Number(split[0]) / Number(split[1]));
}
export function numSuffix(num: number): string {
if (num % 100 >= 11 && num % 100 <= 13) return `${num}th`;
switch (num % 10) {
case 1: return `${num}st`;
case 2: return `${num}nd`;
case 3: return `${num}rd`;
default: return `${num}th`;
}
/**
* Add a suffix to a number:
* 1 = 1st
* 2 = 2nd
* 3 = 3rd
* N = Nth
* @param {number} n
* @returns {string}
*/
export function numSuffix(n: number): string {
const s = ['th', 'st', 'nd', 'rd'], v = n % 100;
return `${n}${s[(v - 20) % 10] || s[v] || s[0]}`;
}