“模块:Hash”的版本间的差异

来自维阿百科
跳转至: 导航搜索
1.38>牛腩面
(导入1个版本)
 
(导入1个版本)
 
(没有差异)

2022年7月8日 (五) 21:15的最新版本

此模块的文档可以在模块:Hash/doc创建

local p = {}

local getArgs = require('Module:Arguments').getArgs

p.main = function(frame)
	local args = getArgs(frame)
	local str = args[1]
	local algo = args[2]
	local algoList = mw.hash.listAlgorithms()
	if algo then
		local isInvalid = true
		for i, v in ipairs(algoList) do
			if algo == v then 
				isInvalid = false
				break
			end
		end
		if isInvalid then
			error('所选的hash算法不可用或无效,所有可用的算法:'..table.concat(algoList, '、'))		
		else
			return mw.hash.hashValue(algo, str)
		end
	else
		return mw.hash.hashValue('md5', str)		
	end
end

return p