Module:ContainsString: Difference between revisions

From Trans People Together Wiki
No edit summary
No edit summary
 
Line 8: Line 8:
     -- plain-text (no pattern) find
     -- plain-text (no pattern) find
     if mw.ustring.find(text, sub, 1, true) then
     if mw.ustring.find(text, sub, 1, true) then
         return true
         return 'matches'
     else
     else
         return
         return ''
     end
     end
end
end


return p
return p

Latest revision as of 17:30, 8 May 2025

Documentation for this module may be created at Module:ContainsString/doc

-- Module:Contains
local p = {}

-- Usage in wikitext: {{#invoke:ContainsString|contains|<full text>|<substring>}}
function p.contains(frame)
    local text   = frame.args[1] or ''
    local sub    = frame.args[2] or ''
    -- plain-text (no pattern) find
    if mw.ustring.find(text, sub, 1, true) then
        return 'matches'
    else
        return ''
    end
end

return p