FANDOM


Torus.util contains utility functions for performing general or common tasks. It is comprised mostly of semantic type converters and string functions. Functions in Torus.util are required to have no side effects - they operate only on their arguments. util functions defined in Core are entirely self contained and do not reference any global variables, however some functions defined by ui.js and UI extensions read from option values.

CoreEdit

The following functions are defined in util.js, and are always available.

debugEdit

Torus.util.debug = function() {
Passes all arguments to console.log.
Return value undefined.
Time complexity O(n) for number of arguments passed

nullEdit

Torus.util.null = function() {
Does nothing.
Return value undefined.
Time complexity O(1)
Notes
  • Intended for use as a valid argument to any function that must accept a function, when no action is intended to be taken.

capEdit

Torus.util.cap = function(str) {
Returns a string that is identical to str, except that the first character is capitalized.
Arguments
  • String str: The string to capitalize.
Return value String: The capitalized string.
Time complexity O(n) for str.length

expiry_to_secondsEdit

Template:Out of date

Torus.util.expiry_to_seconds = function(expiry) {
Converts a logical expiry, such as "2 days", into a number of seconds.
Arguments
  • String expiry: The expiry to convert.
Return value int: The number of seconds.
Notes

seconds_to_expiryEdit

Template:Out of date

Torus.util.seconds_to_expiry = function(seconds) {
Converts a number of seconds into a logical expiry, such as "2 days".
Arguments
  • int seconds: The number of seconds to convert.
Return value String: The logical expiry.
Notes

int_to_stupidEdit

Torus.util.int_to_stupid = function(num) {
Convert an integer to Stupid format.
Arguments
  • int num: The int to convert to Stupid.
Return value String: The Stupid representation of num.
Time complexity O(log10(n)) for num
Notes

stupid_to_intEdit

Torus.util.stupid_to_int = function(str) {
Convert a Stupid string to integer format.
Arguments
  • String str: The Stupid string to convert to an int.
Return value int: The integer representation of str.
Time complexity O(n) for str.length
Notes

load_jsEdit

Torus.util.load_js = function(url) {
Load the script at url on the current page.
Arguments
  • String url: Script URL to load.
Return value HTML <script>: The script tag used to load the script.
Time complexity O(1)
Notes
  • Does not rely on MediaWiki core functions.

load_cssEdit

Torus.util.load_css = function(url) {
Load the stylesheet at url on the current page.
Arguments
  • String url: Stylesheet URL to load.
Return value HTML <link>: The link tag used to load the stylesheet.
Time complexity O(1)
Notes
  • Does not rely on MediaWiki core functions.

UI extensionsEdit

The following util functions are defined by the UI extension and its various sub extensions.

color_hashEdit

Torus.util.color_hash = function(str) {
Convert a string into a hex color.
Arguments
  • String str: The string to hash.
Return value String: A six character hex color, with preceding #.
Time complexity O(n) for str.length

timestampEdit

Torus.util.timestamp = function(time) {
Produce a zero-padded 24 hour timestamp.
Arguments
  • int time: Optional - The time to use for the timestamp. Defaults to the current time.
Return value String: A date formatted hh:mm:ss.
Time complexity O(1)

parse_linksEdit

Torus.util.parse_links = function(text, wiki) {
Expand all links in text into HTML. This includes:
  • Explicit http:// links, eg. http://domain.com
  • External wikilinks, eg. [http://domain.com display text]
  • Internal wikilinks, eg. [[page|display text]], including the pipe trick
  • Interwiki w:c:, wikipedia:, and mediawiki: links, eg. [[w:c:domain:Page|display]]
Arguments
  • String text: The string to process.
  • String wiki: Optional - The domain to process local links for. If left unspecified, local links (eg. [[foo]]) will not be parsed. local.domain can be used to link to pages on the loaded wiki.
Return value String: The same as text, except that wikilinks have been converted to HTML links.
Time complexity O(n) for text.length

normalize_pagenameEdit

Torus.util.normalize_pagename = function(page) {
Normalize page to a standard page name. This includes:
  • Capitalizing the namespace (if not mainspace).
  • Capitalizing the title.
  • Replacing all underscores with spaces.
Arguments
  • String page: The page name to normalize.
Return value String: Normalized page.
Time complexity O(n) for page.length

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.