Yu-Gi-Oh! Wiki
Register
Advertisement
Yu-Gi-Oh! Wiki

High Frequency functions These functions are used often as utilities for other Lua modules. This Module augments the built-in mw.InfoboxBuilderHF from Fandom's Scribunto base. For many of these, there are native Scribunto equivalents, but they are included for compatibility with Fandom's Lua InfoboxBuilder library. See also:


Documentation

Package items

HF.explode(sep, text) (function)
Parameters:
sep (string)
text (string)
Returns: (string)
See also:
HF.isempty(value) (function)
Parameter: value (string|table|nil)
Returns: (boolean)
See also:
HF.firstToUpper(str) (function)
Parameter: str (string)
Returns: (string)
See also:
HF.round(num, idp) (function)
Parameters:
num (number)
idp (number)
Returns: (number)
See also:
HF.trim(s) (function)
Eliminates whitespace from the front and back of a string
Parameter: s (string)
Returns: (string)
See also:
HF.ExternalLink(target, label, plain) (function)
Creates an external link
Parameters:
target (string)
label (string)
plain (boolean; optional)
Returns: (string)
See also:
HF.CategoryLink(category, sortkey, label) (function)
Adds a category and creates a link to the category's page. Combines Category and LinkToCategory.
Parameters:
category (string)
sortkey (string; optional)
label if given, will return a link to the category page (string; optional)
Returns: (string)
See also:
HF.Category(category, sortkey) (function)
Adds a category
Parameters:
category (string)
sortkey (string; optional)
Returns: (string)
See also:
HF.LinkToCategory(category, label) (function)
Creates a link to a category page
Parameters:
category (string)
label (string; optional)
Returns: (string)
See also:
HF.Link(link, text) (function)
Creates an internal link
Parameters:
link (string)
text (string; optional)
Returns: (string)
See also:
HF.Link_safe(object) (function)
Creates an internal link if the linked page exists. Otherwise, returns the page name as text. If given an internal link, will return the link without modification or testing.
Parameter: object (string)
Returns: (string)
See also:
HF.LinkToCategory_safe(object) (function)
Creates an link to a category page if the category exists. Otherwise, returns the page name as text.
Parameter: object (string)
Returns: (string)
See also:
HF.KillNewCategories(object) (function)
Adds a category if the category exists. Otherwise, returns the category name as text.
Parameter: object (string)
Returns: (string)
See also:
HF.unique(raw_table) (function)
Processes a table for unique items
Parameter: raw_table (table)
Returns: (table)
See also:
HF.SMWP(property, value, label) (function)
Adds a SMW inline property
Parameters:
property (string)
value (string)
label (string; optional)
Returns: (string)
HF.NP(title) (function)
Normalize page name
Parameter: title (string)
Returns: (string)

See also



--- High Frequency functions
--  
--  These functions are used often as utilities for other Lua modules.
--   This Module augments the built-in `mw.InfoboxBuilderHF` from Fandom's Scribunto base.
--   For many of these, there are native Scribunto equivalents, but they are included for
--   compatibility with Fandom's Lua InfoboxBuilder library.
--
--
--  See also:
--  * [[mw:Extension:Scribunto/Lua_reference_manual|Lua reference manual]]
--  * [[wikipedia:Wikipedia:Comparable_Lua_functions_to_wikitext|Comparable Lua functions to wikitext]]
--  @module HF
--  @class utility
--  @author [[User:FishTank]]
--  @release stable
--  @require mw.InfoboxBuilderHF
--  @see [[mw:Extension:Scribunto/Lua_reference_manual|Lua reference manual]]
--  @see [[wikipedia:Wikipedia:Comparable_Lua_functions_to_wikitext|Comparable Lua functions to wikitext]]
local HF = mw.InfoboxBuilderHF

---
--  @function HF.explode
--  @param {string} sep
--  @param {string} text
--  @return {string}
--  @see

---
--  @function HF.isempty
--  @param {string|table|nil} value
--  @return {boolean}
--  @see

---
--  @function HF.firstToUpper
--  @param {string} str
--  @return {string}
--  @see

---
--  @function HF.round
--  @param {number} num
--  @param {number} idp
--  @return {number}
--  @see

--- Eliminates whitespace from the front and back of a string
--  @function HF.trim
--  @param {string} s
--  @return {string}
--  @see

--- Creates an external link
--  @function HF.ExternalLink
--  @param {string} target
--  @param {string} label
--  @param[opt] {boolean} plain
--  @return {string}
--  @see

--- Adds a category and creates a link to the category's page.
--  
--   Combines @{HF.Category|Category} and @{HF.LinkToCategory|LinkToCategory}.
--  
--  @function HF.CategoryLink
--  @param {string} category
--  @param[opt] {string} sortkey
--  @param[opt] {string} label
--    if given, will return a link to the category page
--  @return {string}
--  @see


--- Adds a category
--  @function HF.Category
--  @param {string} category
--  @param[opt] {string} sortkey
--  @return {string}
--  @see

--- Creates a link to a category page
--  @function HF.LinkToCategory
--  @param {string} category
--  @param[opt] {string} label
--  @return {string}
--  @see

--- Creates an internal link
--  @function HF.Link
--  @param {string} link
--  @param[opt] {string} text
--  @return {string}
--  @see

--- Creates an internal link
--   if the linked page exists.
--   Otherwise, returns the page name as text.
--   If given an internal link, will return the link
--   without modification or testing. 
--  @function HF.Link_safe
--  @param {string} object
--  @return {string}
--  @see

--- Creates an link to a category page
--   if the category exists.
--   Otherwise, returns the page name as text.
--  @function HF.LinkToCategory_safe
--  @param {string} object
--  @return {string}
--  @see

--- Adds a category
--   if the category exists.
--   Otherwise, returns the category name as text.
--  @function HF.KillNewCategories
--  @param {string} object
--  @return {string}
--  @see

--- Processes a table for unique items
--  @function HF.unique
--  @param {table} raw_table
--  @return {table}
--  @see

--- Adds a SMW inline property
--  @param {string} property
--  @param {string} value
--  @param[opt] {string} label
--  @return {string}
function HF.SMWP( property, value, label )
    if label and (#label > 0) then
        return HF.Link( '%s::%s', label ):format( property, value )
    elseif type(label) == 'string' and ((#label == 0) or label == ' ')then
        return HF.Link( '%s::%s', ' ' ):format( property, value )
    else
        return HF.Link( '%s::%s' ):format( property, value )
    end
end

--- Normalize page name
--  @param {string} title
--  @return {string}
function HF.NP( title )
    title = title or mw.title.getCurrentTitle().prefixedText
    clear =  title:gsub( '"', '\"'):gsub('&','&'):gsub(''', "\'"):gsub('=', '=')
    return clear
end

return HF
Advertisement