Module:utilities/scribunto parameter key
Appearance
- පහත දැක්වෙන උපදෙස්, Module:utilities/scribunto parameter key/documentation හි පිහිටා ඇත. Module:utilities/scribunto parameter key/documentation]]. [සංස්කරණය]
- ප්රයෝජනවත් සබැඳි: root page • root page’s subpages • සබැඳි • transclusions • testcases • sandbox
Takes a parameter name as an input, and returns the Scribunto-normalized form (i.e. the key that that parameter would have in a frame.args
table). For example, "1"
is normalized to 1
(a number), and " foo "
is normalized to "foo"
. If the input is not a string, it is returned unchanged.
Strings are trimmed with Module:string/php trim, and then converted to numbers if:
- They are integers, with no decimals (2.0) or leading zeroes (02).
- They are ≤ 253 and ≥ -253.
- For positive values, they do not have a leading
+
sign.
Note: Lua integers are only accurate to 253 - 1, so 253 and -253 have to be specifically checked for, since 2^53 == 2^53 + 1
evaluates to true
.
local match = string.match
local tonumber = tonumber
local trim = require("Module:string/php trim")
local type = type
return function(key)
if type(key) ~= "string" then
return key
end
key = trim(key)
if match(key, "^-?[1-9]%d*$") then
local num = tonumber(key)
return (
num <= 9007199254740991 and num >= -9007199254740991 or
key == "9007199254740992" or
key == "-9007199254740992"
) and num or key
elseif key == "0" then
return 0
end
return key
end