This module Houses general purpose string functions for ease of use in other modules.
Loading the module
To load this module, Add this line of code to the start of your module:
local string = require('Module:String')
All methods described below will be available under the loaded table.
Methods
All methods are available below as fields under the required object name.
- NOTE: All functions described here are NOT part of the original lua string library. they are stored under this object for simplicity.
string.ucfirst
string.ucfirst(<string>(string))
This method returns <string> with the first letter of every word to upper case.
string.lcfirst
string.lcfirst(<string>(string))
This method works exactly like string.ucfirst(), but with every letter of the first word being uppercase.
string.blankCell
string.blankCell()
This method returns a HTML blank cell like {{blank cell}}.
string.infoNeeded
string.infoNeeded()
This method returns a info needed text like {{InfoNeeded}}.
string.reverseSymbol
string.reverseSymbol(<string>(string), <reverse>(boolean))
This method returns a copy of <string> with certain characters like [ or { replaced with their flipped counterparts. It also reverses the returned string with string.reverse() if the parameter <reverse> is set to true.
string.pcall
string.pcall(<function>(function), ...(any, NR))
This method calls <function> with the arguments as set in <...>. If no error is raised in calling the function, all values returned by <function> are returned. Else, it returns the error message as a template error.
string.makeTitle
string.makeTitle(<s>(string), <title>(string), <options>(table, NR))
This method returns a HTML <abbr> element (<span> if <options.disableAbbr> is set to true) with the title attribute set to the text of <title> and the inner text as <s>. If <options.ignoreTitleNil> is set to true, <title> is not required (otherwise required).
string.parseDualArg
string.parseDualArg(<val>(string, table, number))
This method returns the value if it is a string, if it is a table, it concatenates it with table.concat() with an empty string as a default parameter or the sep field in the provided table, if it is a number, it converts it to a string.
string.wrapLink
string.wrapLink(<page>(string), <alt>(string, NR))
This method returns a wikilink with <page> as the link target, and <alt> as the display text.
string.externalUrl
string.externalUrl(<url>(string), <query>(string, NR), <alt>(string, NR))
This method returns an external link to a external website provided by <url> with <query> as an optional URL query and optional alternate text provided by <alt>.
string.fullUrl
string.fullUrl(<page>(string), <query>(string, NR), <alt>(string, NR))
This method returns an internal URL to a page provided by <page> with <query> as an optional URL query and optional alternate text provided by <alt> in a similar fashion to string.externalUrl().
string._repeat
string._repeat(<s>(string), <num>(number), <sep>(string, NR))
This method takes the string in <s> and repeats it according to the delimiter <num> separated by the text specified in <sep> if it is omitted.
string.wrapHtml
string.wrapHtml(<s>(string), <tag>(string), <attrs>(table, NR))
Alternative Calls:
- wrapHtml({ <s>(string), <tag>(string), <attrs>(table, NR) })
- wrapHtml({ text = <s>(string), tag = <tag>(string), attrs = <attrs>(table, NR) })
This method is provided as a light-weight alternative to mw.html.create(). If you need to make more complex elements like tables, use mw.html.create().
The function returns <s> wrapped by the html element with the tag name specified in <tag> with the attributes in <attrs> if the parameter is omitted.
There are special cases for attributes:
- Class: - The class names for the element can be just a string, or it can be an table of classes. If the input is a table, the keys in the arrays are joined by spaces.
- Style: - The css rule can be just a string, or it can be a table. In the case of the attribute being a table, the attribute is a CSS rule with the table key as the CSS property name, and the value as the CSS value of the omitted property.
Examples
- Regular example
string.wrapHtml('Foo', 'span', {style="color:red"})
Produces:
Foo
- Table function call
string.wrapHtml{
text='Foo',
tag='span',
style='color: red; font-weight: bold;'
}
Produces:
Foo
- Special Attribute values
string.wrapHtml{
text='Foo',
tag='span',
style={
color="red";
font-weight="bold";
}
}
Produces:
Foo
string._formatShortNum
string._formatShortNum(<num>(string))
This method returns a short formatted version of <num> like 10k.
string._toNumber
string._toNumber(<num>(string))
This method converts a string (can be a formatted number returned by the method above) to a number using tonumber().
string._formatNum
string._formatNum(<num>(string))
This method converts <num> to a formatted number using mw.language.getContentLangauge():formatNum().
string.error
string.error(<msg>(string), ...(string, number))
This method returns a string as a template error with <msg> and <...> as arguments to string.format()
string.centerText
string.centerText(<s>(string))
This method returns a <div> element that aligns the text to the center of an element using string.wrapHtml().
string._toRoman
string._toRoman(<string>(string))
This method returns a copy of <string> with numbers converted to roman numerals.
string._toArabic
string._toArabic(<string>(string))
This method returns a copy of <string> with roman numerals converted to numbers. Basically it is a oposite of string._toRoman().
string._splitNameAndTier
string._splitNameAndTier(<str>(string))
This method extracts a name and tier from the target string <str>. It returns a table with 2 values, the first being the name, the second being the tier.
string._lorem
string.lorem(<num>(number))
Currently not working!
This method returns a lorem sample text based on the length of <num>.
string.roundNumber
string.roundNumber(<num>(number), <posistion>(number, NR))
This method returns <num> rounded to the number of decimal places specified by <num>.
<num> defaults to 1.
string._delDoubleSpace
string.delDoubleSpace(<s>(string))
This method returns a copy of <s> with all duplicate spaces removed using the following lua pattern: (%s)%s* with the replacement being %1.
Submodules
See Also
| Hypixel SkyBlock Wiki Standard Lua Libraries (hsw/stdll) v · d · e | |
| Type | Libraries |
|---|---|
| Module Loading Utilities |
|
| General Utilities |
|
| Meta Modules | |
| Object-oriented |
|
| Caching | |