Jump to content

Module:anagrams

From Wiktionary, the free dictionary

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

local m_links = require("Module:links")
local m_track = require("Module:debug/track")

local export = {}

local function check_alphagram(alphagram)
	local prev = 0
	alphagram = alphagram:gsub("%s", "")
	for char in mw.ustring.gcodepoint(alphagram) do
		local sort = tonumber(char)
		if prev > sort then
			return false
		end
		prev = sort
	end
	return true
end

function export.show(frame)
	local params = {
		[1] = {required = true, type = "full language", default = "und"},
		[2] = {required = true, default = "anagram", list = true},
		["a"] = true,
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	if mw.title.getCurrentTitle().isContentPage then
		if args.a and not check_alphagram(args.a) then
			m_track("anagrams/invalid alphagram")
		end
	end
	
	for i, val in ipairs(args[2]) do
		args[2][i] = m_links.full_link({lang = args[1], term = val})
	end

	return table.concat(args[2], ", ")
end

return export