<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://cherry-pi.tailb1a250.ts.net/index.php?action=history&amp;feed=atom&amp;title=Module%3AInfoboxLua%2FUtil</id>
	<title>Module:InfoboxLua/Util - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://cherry-pi.tailb1a250.ts.net/index.php?action=history&amp;feed=atom&amp;title=Module%3AInfoboxLua%2FUtil"/>
	<link rel="alternate" type="text/html" href="https://cherry-pi.tailb1a250.ts.net/index.php?title=Module:InfoboxLua/Util&amp;action=history"/>
	<updated>2026-11-11T03:28:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://cherry-pi.tailb1a250.ts.net/index.php?title=Module:InfoboxLua/Util&amp;diff=361&amp;oldid=prev</id>
		<title>Gravy: Created page with &quot;require( &#039;strict&#039; )  local libraryUtil = require( &#039;libraryUtil&#039; ) local checkType = libraryUtil.checkType local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg  local p = {}   --- Checks if a value is a string and is not empty. --- --- @param value any The value to check. --- @return boolean True if the value is a non-empty string, false otherwise. function p.isNonEmptyString( value ) 	return type( value ) == &#039;string&#039; and value ~= &#039;&#039; end  --- Checks if a value is...&quot;</title>
		<link rel="alternate" type="text/html" href="https://cherry-pi.tailb1a250.ts.net/index.php?title=Module:InfoboxLua/Util&amp;diff=361&amp;oldid=prev"/>
		<updated>2026-06-14T02:19:52Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;require( &amp;#039;strict&amp;#039; )  local libraryUtil = require( &amp;#039;libraryUtil&amp;#039; ) local checkType = libraryUtil.checkType local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg  local p = {}   --- Checks if a value is a string and is not empty. --- --- @param value any The value to check. --- @return boolean True if the value is a non-empty string, false otherwise. function p.isNonEmptyString( value ) 	return type( value ) == &amp;#039;string&amp;#039; and value ~= &amp;#039;&amp;#039; end  --- Checks if a value is...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require( &amp;#039;strict&amp;#039; )&lt;br /&gt;
&lt;br /&gt;
local libraryUtil = require( &amp;#039;libraryUtil&amp;#039; )&lt;br /&gt;
local checkType = libraryUtil.checkType&lt;br /&gt;
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--- Checks if a value is a string and is not empty.&lt;br /&gt;
---&lt;br /&gt;
--- @param value any The value to check.&lt;br /&gt;
--- @return boolean True if the value is a non-empty string, false otherwise.&lt;br /&gt;
function p.isNonEmptyString( value )&lt;br /&gt;
	return type( value ) == &amp;#039;string&amp;#039; and value ~= &amp;#039;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Checks if a value is a table and is not empty.&lt;br /&gt;
---&lt;br /&gt;
--- @param value any The value to check.&lt;br /&gt;
--- @return boolean True if the value is a non-empty table, false otherwise.&lt;br /&gt;
function p.isNonEmptyTable( value )&lt;br /&gt;
	return type( value ) == &amp;#039;table&amp;#039; and value ~= {}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Validates input data against a provided schema and constructs a new object.&lt;br /&gt;
--- Returns nil if validation fails.&lt;br /&gt;
---&lt;br /&gt;
--- @param rawData table&lt;br /&gt;
--- @param schema DataSchemaDefinition&lt;br /&gt;
--- @return table|nil&lt;br /&gt;
function p.validateAndConstruct( rawData, schema )&lt;br /&gt;
	checkType( &amp;#039;Util.validateAndConstruct&amp;#039;, 1, rawData, &amp;#039;table&amp;#039; )&lt;br /&gt;
	checkType( &amp;#039;Util.validateAndConstruct&amp;#039;, 2, schema, &amp;#039;table&amp;#039; )&lt;br /&gt;
&lt;br /&gt;
	local newObject = {}&lt;br /&gt;
&lt;br /&gt;
	for key, schemaDef in pairs( schema ) do&lt;br /&gt;
		checkType( &amp;#039;Util.validateAndConstruct (schema validation for key: &amp;#039; .. tostring( key ) .. &amp;#039;)&amp;#039;, 1, schemaDef,&lt;br /&gt;
			&amp;#039;table&amp;#039; )&lt;br /&gt;
		checkTypeForNamedArg( &amp;#039;Util.validateAndConstruct (schema validation for key: &amp;#039; .. tostring( key ) .. &amp;#039;)&amp;#039;, &amp;#039;type&amp;#039;,&lt;br /&gt;
			schemaDef.type, &amp;#039;string&amp;#039; )&lt;br /&gt;
		if schemaDef.required ~= nil then&lt;br /&gt;
			checkTypeForNamedArg( &amp;#039;Util.validateAndConstruct (schema validation for key: &amp;#039; .. tostring( key ) .. &amp;#039;)&amp;#039;,&lt;br /&gt;
				&amp;#039;required&amp;#039;, schemaDef.required, &amp;#039;boolean&amp;#039;, true )&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		local value = rawData[key]&lt;br /&gt;
&lt;br /&gt;
		if schemaDef.required and value == nil then&lt;br /&gt;
			error( &amp;#039;Input data missing required key: &amp;#039; .. tostring( key ) )&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if value ~= nil then&lt;br /&gt;
			checkTypeForNamedArg( &amp;#039;Util.validateAndConstruct&amp;#039;, tostring( key ), value, schemaDef.type, false )&lt;br /&gt;
			newObject[key] = value&lt;br /&gt;
		elseif schemaDef.default ~= nil then&lt;br /&gt;
			newObject[key] = schemaDef.default&lt;br /&gt;
		else&lt;br /&gt;
			if schemaDef.required == false then&lt;br /&gt;
				newObject[key] = nil&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	for key, _ in pairs( rawData ) do&lt;br /&gt;
		if not schema[key] then&lt;br /&gt;
			error( &amp;#039;Input data contains extraneous key not defined in schema: &amp;#039; .. tostring( key ) )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return newObject&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Helper function to fix arrays from a JSON loaded with mw.loadJsonData.&lt;br /&gt;
---&lt;br /&gt;
--- @param array table The array to fix.&lt;br /&gt;
--- @return table The fixed array.&lt;br /&gt;
function p.fixJsonArray( array )&lt;br /&gt;
	if array == nil then&lt;br /&gt;
		return {}&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	checkType( &amp;#039;Util.fixJsonArray&amp;#039;, 1, array, &amp;#039;table&amp;#039; )&lt;br /&gt;
&lt;br /&gt;
	local parts = {}&lt;br /&gt;
	for _, value in ipairs( array ) do&lt;br /&gt;
		table.insert( parts, value )&lt;br /&gt;
	end&lt;br /&gt;
	return parts&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Gravy</name></author>
	</entry>
</feed>