local z=require(script.Parent.Parent.lib.t)local Y=require(script.Parent.Parent.generic.getSortedKeys)local Z=z.tuple(z.any,z.optional(z.integer))local function a(z,U)assert(Z(z,U))U=U or 0 local G={}local X="    "if typeof(z)=="\116\097\098\108\101"then table.insert(G,"\123\n")for Y,Z in pairs(Y(z))do local I=X:rep(U+1)local f=a(z[Z],U+1)table.insert(G,("\037\115 \037\115 \061 \037\115\n"):format(I,Z,f))end table.insert(G,("\037\115\125"):format(X:rep(U)))elseif typeof(z)=="\115\116\114\105\110\103"then table.insert(G,("\037\113 \040\115\116\114\105\110\103\041"):format(z))else table.insert(G,("\037\115 \040\037\115\041"):format(tostring(z),typeof(z)))end return table.concat(G)end return a
--[[
	Converts a value into a nicely formatted string.

	This is mostly used for tables as a way to inspect the contents. inspect.lua
	is the next best thing, but is a bit slow and bogs things down if used in
	succession. This function is a lot more lightweight.

	Usage:

		local t = {
			foo = true,
			bar = false
		}

		print(pretty(t))
]]

local t = require(script.Parent.Parent.lib.t)
local getSortedKeys = require(script.Parent.Parent.generic.getSortedKeys)

local prettyCheck = t.tuple(t.any, t.optional(t.integer))
local function pretty(value, indentLevel)
	assert(prettyCheck(value, indentLevel))

    indentLevel = indentLevel or 0

    local output = {}
    local indent = "    "

    if typeof(value) == "table" then
        table.insert(output, "{\n")

        for _, k in pairs(getSortedKeys(value)) do
			local indentation = indent:rep(indentLevel+1)
			local otherValue = pretty(value[k], indentLevel+1)

			table.insert(output, ("%s %s = %s\n"):format(indentation, k, otherValue))
        end

        table.insert(output, ("%s}"):format(indent:rep(indentLevel)))
    elseif typeof(value) == "string" then
		table.insert(output, ("%q (string)"):format(value))
    else
		table.insert(output, ("%s (%s)"):format(tostring(value), typeof(value)))
    end

    return table.concat(output)
end

return pretty
