added to_boolean

This commit is contained in:
VorTechnix 2021-10-10 14:39:30 -07:00
parent bc0658b545
commit b72d36816e
2 changed files with 13 additions and 0 deletions

@ -4,3 +4,4 @@ dofile(wea.modpath.."/utils/strings/split.lua")
dofile(wea.modpath.."/utils/strings/polyfill.lua")
dofile(wea.modpath.."/utils/strings/tochars.lua")
wea.split_shell = dofile(wea.modpath.."/utils/strings/split_shell.lua")
wea.to_boolean = dofile(wea.modpath.."/utils/strings/to_boolean.lua")

@ -0,0 +1,12 @@
--- Converts input to a value of type Boolean.
-- @param arg any Input to convert
-- @returns boolean
local function to_boolean(arg)
local typ = type(arg)
if typ == "boolean" then return arg
elseif typ == number and arg > 0 then return true
elseif arg == "false" or arg == "no" then return false
elseif typ ~= "nil" then return true
else return false end
end
return to_boolean