From 94bf4a4276633371b5bb648b8840d808ec546d49 Mon Sep 17 00:00:00 2001 From: rootiest Date: Tue, 24 Sep 2024 14:51:42 -0400 Subject: [PATCH] feat: add function to get the appropriate ordinal suffix for a given number --- lua/data/func.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lua/data/func.lua b/lua/data/func.lua index 29f406b..f592da2 100644 --- a/lua/data/func.lua +++ b/lua/data/func.lua @@ -1149,6 +1149,26 @@ function M.get_bg_color(hlgroup) return nil end +---@function Function to get the appropriate ordinal suffix for a given number. +---@param number number The number to check for the ordinal suffix. +---@return string The number with its ordinal suffix. +function M.get_ordinal_suffix(number) + -- Determine the last two digits to handle 'teen' cases correctly + local suffix = "th" -- Default suffix + local last_digit = number % 10 + local last_two_digits = number % 100 + + if last_digit == 1 and last_two_digits ~= 11 then + suffix = "st" + elseif last_digit == 2 and last_two_digits ~= 12 then + suffix = "nd" + elseif last_digit == 3 and last_two_digits ~= 13 then + suffix = "rd" + end + + return tostring(number) .. suffix +end + ---@function Function to check if the window is wide enough ---@param width_limit number The minimum width of the window ---@return boolean condition true if the window is wide enough, false otherwise