Module:number utilities

Hello, you have come here looking for the meaning of the word Module:number utilities. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:number utilities, but we will also tell you about its etymology, its characteristics and you will know how to say Module:number utilities in singular and plural. Everything you need to know about the word Module:number utilities you have here. The definition of the word Module:number utilities will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:number utilities, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

function export.get_number(text)
	if text == '' or text == nil then return nil end
	
	if type(text) == 'string' then
		text = mw.ustring.gsub(text, ",", "")
	end
	
	local j = tonumber(text)
	if j ~= nil then
		return j
	else
		return nil
	end
end

function export.is_number(frame)
	return export.get_number(frame:getParent().args)
end

function export.is_hex_number(frame)
	local args = frame:getParent().args
	local hex = args
	if hex then
		hex = mw.text.trim(hex)
		if hex:find("^%x*$") then
			if args.digits then
				local digits = tonumber(args.digits)
				if digits then
					if #hex == digits then
						return "1"
					elseif #hex == 0 and args.allow_empty then
						return "1"
					else
						return ""
					end
				else
					error("Invalid number " .. digits)
				end
			else
				return "1"
			end
		else
			return ""
		end
	else
		if args.allow_empty then
			return "1"
		else
			return ""
		end
	end
end

return export