Premium support for our pure JavaScript UI components


Post by gbrdhvndi »

The current implementation of the ordinalSuffix function in the default English locale assumes all numbers ending with 1, 2, or 3 to have "st", "nd", and "rd" suffices respectively leaving all remaining numbers with a "th" suffix.

const ordinalSuffix = (number) =>
  number + ({ 1: "st", 2: "nd", 3: "rd" }[number[number.length - 1]] || "th");

Quokka sample:

ordinalSuffix.png
ordinalSuffix.png (135.66 KiB) Viewed 694 times

However, this isn't a valid assumption as numbers 11, 12, and 13 (as well as 111, 112, 113, 1011, 1012, 1013, and so on) should all have the "th" suffix.

Therefore, the function should be applying special treatment to any numbers ending with 11, 12, and 13.

const ordinalSuffixProper = (number) =>
  number +
  ((!["11", "12", "13"].find((n) => number.endsWith(n)) &&
    { 1: "st", 2: "nd", 3: "rd" }[number[number.length - 1]]) ||
    "th");

Quokka sample:

ordinalSuffixProper.png
ordinalSuffixProper.png (184.94 KiB) Viewed 694 times

Aleksei


Post by alex.l »

Hi gbrdhvndi,

Thanks for the report! The ticket is here: https://github.com/bryntum/support/issues/2039

All the best,
Alex

All the best,
Alex


Post Reply