Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Utilities

From Sekaipedia
Revision as of 06:11, 13 August 2021 by ChaoticShadow (talk | contribs)

Documentation for this module may be created at Module:Utilities/doc

local utilities = {}

-- https://stackoverflow.com/questions/1426954/split-string-in-lua
function utilities.split(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t = {}
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        table.insert(t, str)
    end
    return t
end

function utilities.trim(str)
	return string.gsub(str, "^%s*(.-)%s*$", "%1")
end

function utilities.capitalize(str)
	return str:sub(1, 1):upper() .. str:sub(2, -1)
end

function utilities.array_index_of(arr, val)
    for i,v in ipairs(arr) do
        if v == val then
            return i
        end
    end

    return -1
end

-- https://stackoverflow.com/questions/49907620/how-to-fuse-array-in-lua/49908683
function utilities.table_concat(a, b)
	local result = {unpack(a)}
	for k,v in pairs(b) do
		result[k] = v
	end
	return result
end


return utilities
Cookies help us deliver our services. By using our services, you agree to our use of cookies.