ਮੌਡਿਊਲ:Convert/helperDocumentation for this module may be created at ਮੌਡਿਊਲ:Convert/helper/doc -- This module provides some functions to prepare template parameters
-- for use with Template:Convert.
-- This module is not used by Template:Convert or Module:Convert.
local function stripToNil(text)
-- If text is a non-empty string, return its trimmed content,
-- otherwise return nothing (empty string or not a string).
if type(text) == 'string' then
return text:match('(%S.-)%s*$')
end
end
-- Format regular input with fraction (MOS-confirmant) into Convert-format "12+3/8" ("+" added).
-- First usage in Template:NFL_predraft (August 2017)
local function number(frame)
--[[ Preprocess a template parameter to translate a number to be used as
input for {{convert}}.
{{#invoke:convert/helper|number|12 3/8}} → 12+3/8
Input Output
12 12
12 3/8 12+3/8
{{frac|12|3|8}} 12+3/8
12{{frac|3|8}} 12+3/8
12⅜ 12+3/8
Template:Fraction redirects to Template:Frac so either may be used in the input.
]]
local args = frame.args
local text = stripToNil(args[1]) or ''
if text == '' or tonumber(text) then
return text -- examples: '', '12', '12.3', '12.3e4', or negative
end
text = text:gsub(' ', ' '):gsub(' +', ' '):gsub(' *%+ *', '+'):gsub('⁄', '/'):gsub('⁄', '/')
local integer, numerator, denominator, rest
-- Look for a fraction of form '12 3/8' or '12+3/8' or '3/8'.
integer, numerator, denominator = text:match('^(%d+)[ +](%d+)/(%d+)$')
if integer then
return integer .. '+' .. numerator .. '/' .. denominator
end
numerator, denominator = text:match('^(%d+)/(%d+)$')
if numerator then
return numerator .. '/' .. denominator
end
-- Look for an expanded fraction such as the result of {{frac|12|3|8}} or 12{{frac|3|8}} or {{frac|3|8}}.
numerator, denominator = text:match('<sup>(%d+)</sup>/<sub>(%d+)</sub></span>')
if numerator then
integer = text:match('(%d+)<span class="visualhide">') or
text:match('^(%d+)%s*​<span') or -- Template:Frac outputs zwsp since December 2017
text:match('^(%d+)%s*<span')
return (integer and (integer .. '+') or '') .. numerator .. '/' .. denominator
end
-- Look for a fraction of form '12¾' or '¾'.
local fractions = {
['½'] = '1/2',
['⅓'] = '1/3',
['⅔'] = '2/3',
['¼'] = '1/4',
['¾'] = '3/4',
['⅛'] = '1/8',
['⅜'] = '3/8',
['⅝'] = '5/8',
['⅞'] = '7/8',
}
integer, rest = text:match('^(%d*)%s*(.*)')
local expand = fractions[rest]
if expand then
return (integer == '' and integer or (integer .. '+')) .. expand
end
return text
end
return {
number = number,
}
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia