Module:Utils: Difference between revisions
m minor renaming of args |
Fix for clamp. Improve documentation |
||
| (2 intermediate revisions by one other user not shown) | |||
| Line 3: | Line 3: | ||
local get_args = require("Module:Arguments").getArgs | local get_args = require("Module:Arguments").getArgs | ||
local yesno = require("Module:Yesno") | local yesno = require("Module:Yesno") | ||
-- TODO??? Enforce rule for prefixing module-callable functions with an | |||
-- underscore, regardless of whether a wrapper is needed or can be made???? | |||
-- Trim a string (remove leading and trailing, but not interior, whitespace) | -- Trim a string (remove leading and trailing, but not interior, whitespace) | ||
| Line 12: | Line 15: | ||
function p._yesno(frame) | function p._yesno(frame) | ||
return yesno(frame.args["input"], frame.args["default"]) | return yesno(frame.args["input"], frame.args["default"]) | ||
end | |||
-- Clamp function | |||
-- Underscore-prefixed in case a wrapper for a template is ever needed | |||
function p._clamp(value, min_value, max_value) | |||
return math.min(math.max(value, min_value), max_value) | |||
end | end | ||
| Line 63: | Line 72: | ||
end | end | ||
-- | -- Parse a ratio string like "3/2" into a number | ||
-- Use default on error; cannot be used with {{#invoke:}} | |||
function p.eval_num_arg(input, def_value) | function p.eval_num_arg(input, def_value) | ||
local result = input | local result = input | ||