Skip to content

Commit

Permalink
feat: use size and time default transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasmus-Bertell committed Nov 27, 2023
1 parent 7184d14 commit d60951c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lua/rest-nvim/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ local transform = {
return time .. " " .. units[unit]
end,

byte = function(bytes)
size = function(bytes)
bytes = tonumber(bytes)

local units = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB" }
Expand Down Expand Up @@ -600,6 +600,12 @@ M.parse_statistics = function(body)
if type(tbl.type) == "function" then
value = tbl.type(value)
end
else
for key, fun in pairs(transform) do
if string.match(tbl[1], "^" .. key) then
value = fun(value)
end
end
end

table.insert(out, (tbl.title or (tbl[1] .. " ")) .. value)
Expand Down

0 comments on commit d60951c

Please sign in to comment.