User:Gurch/Snuggle documentation

apply
(function, object, ...) → object

Evaluates the specified function with remaining parameters as arguments.

assign (:=)
(string, object) → object

Assigns a value to an identifier. Returns the value that was assigned.

boolean
object → boolean

Returns boolean representation of argument.

function
(args:object, ..., expression:object) → function

Returns a function. expression is expression to be evaluated, args are identifiers appearing in expression, which are substituted for argument values when the function is called.

if
(boolean, object, object) → object

<tt>(boolean, object) → object</tt>

If first argument is true, evaluates and returns second argument, otherwise evaluates and returns third argument, or false if no third argument is provided. Does not evaluate the argument that is not returned.

is
<tt>(object, string) → boolean</tt>

Returns true if argument 1 is of type given by argument 2, otherwise false.

number
<tt>object → number</tt>

Returns numeric representation of argument.

sequence
<tt>(object, ...) → object</tt>

Evaluates arguments in order, returns value of last one.

string
<tt>object → string</tt>

Returns string representation of argument.

switch
<tt>(value:object, {test:object, expression:object}...) → object</tt>

Conditionally evaluates one or more expressions based on <tt>value</tt>. Arguments following first are in pairs; for each pair, if <tt>test</tt> is equal to <tt>value</tt>, <tt>expression</tt> is evaluated. Last expression evaluated is returned. <tt>test</tt> can be a list, in which case <tt>expression</tt> will be evaluated if any item in <tt>test</tt> is equal to <tt>value</tt>.

type
<tt>object → string</tt>

Returns type of argument.

wikitext
<tt>object → string</tt>

Return wikitext representation of argument.

not (!)
<tt>boolean → boolean</tt>

Logical 'not' operator.

and (&)
<tt>(boolean, boolean) → boolean</tt>

Logical 'and' operator. Short-circuiting: evaluates from left to right, arguments following a false value not evaluated.

or (|)
<tt>(boolean, boolean) → boolean</tt>

Logical 'or' operator. Short-circuiting: evaluates from left to right, arguments following a true value not evaluated.

xor
<tt>(boolean, boolean) → boolean</tt>

Logical 'exclusive-or' operator.

=
<tt>(object, object) → boolean</tt>

Returns true if string representations of objects are equal, otherwise false.

!=
<tt>(object, object) → boolean</tt>

Returns false if string representations of objects are equal, otherwise true.

>
<tt>(number, number) → boolean</tt>

Returns true if first argument greater than second, otherwise false.

<
<tt>(number, number) → boolean</tt>

Returns true if first argument less than second, otherwise false.

>=
<tt>(number, number) → boolean</tt>

Returns true if first argument greater than or equal to second, otherwise false.

<=
<tt>(number, number) → boolean</tt>

Returns true if first argument less than or equal to second, otherwise false.

+=
<tt>(string, number) → number</tt>

Increments value of specified identifier by specified number and returns result.

-=
<tt>(string, number) → number</tt>

Decrements value of specified identifier by specified number and returns result.

sum (+)
<tt>(number, ...) → number</tt>

Returns sum of arguments.

sub (-)
<tt>(number, number) → number</tt>

Subtracts second argument from first.

*
<tt>(number, number) → number</tt>

Multiplies arguments.

/
<tt>(number, number) → number</tt>

Divides first argument by second.

div (\)
<tt>(number, number) → number</tt>

Divides first argument by second, returns integer part of result.

mod (%)
<tt>(number, number) → number</tt>

Divides first argument by second, returns integer remainder.

pow (^)
<tt>(number, number) → number</tt>

Returns first argument raised to power of second argument.

abs
<tt>number → number</tt>

Returns absolute value of argument.

sign
<tt>number → number</tt>

Returns sign of argument.

sqrt
<tt>number → number</tt>

Returns square root of argument.

max
<tt>(number, ...) → number</tt>

Returns maximum of arguments.

min
<tt>(number, ...) → number</tt>

Returns minimum of arguments.

log
<tt>number → number</tt>

Returns logarithm to base 10 of argument.

ln
<tt>number → number</tt>

Returns natural logarithm of argument.

classify
<tt>(number, number) → string</tt>

Accepts value and interval size; returns string representation of interval of that size to which value belongs.

+
<tt>(string, string) → string</tt>

Concatenates two strings.

&=
<tt>(string, string) → string</tt>

Concatenates the value of identifier in first argument with second argument, assigns result to identifier and returns result.

contains
<tt>(string, string) → boolean</tt>

Returns true if first argument contains second, otherwise false.

lower
<tt>string → string</tt>

Returns argument transformed to lowercase.

upper
<tt>string → string</tt>

Returns argument transformed to uppercase.

lowerfirst
<tt>string → string</tt>

Returns argument with first character transformed to lowercase.

upperfirst
<tt>string → string</tt>

Returns argument with first character transformed to uppercase.

length
<tt>string → number</tt>

Returns length of argument.

empty
<tt>string → boolean</tt>

Returns true if argument is of length zero, otherwise false.

startswith
<tt>(string, string) → boolean</tt>

Returns true if first argument starts with second argument, otherwise false.

endswith
<tt>(string, string) → boolean</tt>

Returns true if first argument ends with second argument, otherwise false.

replace
<tt>(string, string, string) → string</tt>

Returns first argument with all instances of second argument replaced by third argument.

like
<tt>(string, string) → boolean</tt>

Returns true if regex pattern given by second argument matches whole of first argument, otherwise false.

match
<tt>(string, string) → string</tt>

<tt>(string, string, number) → string</tt>

With two arguments, returns first occurence of regex pattern given by second argument in first argument, or empty string if no match. With three arguments, occurence specified by third argument is returned, or empty string if there are insufficient matches.

replacepattern
<tt>(string, string, string) → string</tt>

Returns first argument with regex search pattern and replace pattern in second and third arguments applied.

date
<tt>object → date</tt>

Returns date representation of argument.

dayname
<tt>date → string</tt>

Returns name of day of week.

dayofmonth
<tt>date → number</tt>

Returns day of month.

dayofweek
<tt>date → number</tt>

Returns day of week.

dayofyear
<tt>date → number</tt>

Returns day of year.

fullday
<tt>date → string</tt>

Returns day, month name and year.

fullmonth
<tt>date → string</tt>

Returns month name and year.

fullweek
<tt>date → string</tt>

Returns week number and year.

hour
<tt>date → number</tt>

Returns hour component of argument.

minute
<tt>date → number</tt>

Returns minute component of argument.

month
<tt>date → number</tt>

Returns month number.

monthname
<tt>date → string</tt>

Returns name of month.

second
<tt>date → number</tt>

Returns second component of argument.

week
<tt>date → number</tt>

Returns week number.

year
<tt>date → number</tt>

Returns year number.

list
<tt>(object, ...) → list</tt>

Returns list constructed from arguments.

count
<tt>list → number</tt>

Returns number of items in list.

sort
<tt>list → list</tt>

Sorts argument, contents must all be of same type.

unique
<tt>list → list</tt>

Returns argument with any duplicate values removed.

group
<tt>list → table(object, number)</tt>

Returns a table listing each unique value in argument and the number of occurences.

groupby
<tt>(list, expression) → table(object, number)</tt>

Applies expression to each value in list, then applies <tt>group</tt> to results.

exclude
<tt>(list, list) → list</tt>

Returns first argument with any values that occur in second argument removed.

union
<tt>(list, list) → list</tt>

Returns list containing values from both arguments, including duplicates.

merge
<tt>(list, object) → list</tt>

Appends object in second argument to list given by first argument.

first
<tt>list → object</tt>

Returns first value in argument.

rest
<tt>list → list</tt>

Returns argument with first value removed.

last
<tt>list → object</tt>

Returns last value in argument.

item
<tt>(list, number) → object</tt>

Returns value in first argument at zero-based index given by second argument

limit
<tt>(list, number) → list</tt>

Returns number of items given by second argument from first argument, or entire list if shorter.

range
<tt>(list, number, number) → list</tt>

Returns subset of items from argument 1, of size given by argument 3 and beginning at index given by argument 2.

reverse
<tt>list → list</tt>

Returns argument with items reversed.

filter
<tt>(list, expression) → list</tt>

Evaluates expression in the context of each item in the list, returns list of items for which expression evaluates to true.

map (->)
<tt>(list, expression) → list</tt>

Evaluates expression in the context of each item in the list, returns list of results.

fold
<tt>(list, string) → object</tt>

<tt>(list, string, object) → object</tt>

Starts with third argument or default value as result and iteratively applies function given by string to next item in list. See fold (higher-order function).

movingavg
<tt>(list:list, size:number) → list</tt>

Returns list of averages of each set of <tt>size</tt> consecutive values in <tt>list</tt>. Length of resulting list is list <tt>count(list) - size + 1</tt>.

table
<tt>(list, expression, ...) → table</tt>

Evaluates each expression given in the context of each item in list and constructs a table of resulting values. Table contains one row for each item in list and one column for each expression. Parameter names given for expressions will be used as column names.

count
<tt>table → number</tt>

Returns number of rows in argument.

column
<tt>(table, number) → list</tt>

<tt>(table, string) → list</tt>

Returns list of values in table column given by column index or name.

columncount
<tt>table → number</tt>

Returns number of columns in argument.

sortby
<tt>(table, number) → table</tt>

<tt>(table, string) → table</tt>

Sorts table by column index or name.

category
<tt>string → category</tt>

Returns category with name given by argument.

hidden
<tt>category → boolean</tt>

Returns true if category is hidden, otherwise false.

count
<tt>category → number</tt>

Returns number of items in category.

subcatcount
<tt>category → number</tt>

Returns number of subcategories in category.

page
<tt>string → page</tt>

Returns page with name given by argument.

::
<tt>(page:page, param:string) → string</tt>

Infobox lookup. Returns value of parameter <tt>param</tt> in infobox on <tt>page</tt>, with reference to parameter normalization table. Returns <tt> </tt> if <tt>page</tt> has no infobox, <tt> </tt> if <tt>page</tt> has an infobox but it does not contain parameter <tt>param</tt>.

assessment
<tt>page → string</tt>

Returns assessment level of page.

basename
<tt>page → string</tt>

Returns page name without namespace prefix.

categories
<tt>page → list</tt>

Returns list of categories that current version of page is in.

creator
<tt>page → user</tt>

Returns creator of page.

firstedit
<tt>page → revision</tt>

Returns first revision of page.

hasinfobox
<tt>page → boolean</tt>

Returns true if current version of page has an infobox, otherwise false.

infobox
<tt>page → templateinstance</tt>

Returns infobox on current version of page, if any.

isarticle
<tt>page → boolean</tt>

Returns true if page is article, otherwise false.

isarticletalkpage
<tt>page → boolean</tt>

Returns true if page is article talk page, otherwise false.

isredirect
<tt>page → boolean</tt>

Returns true if current version of page is a redirect, otherwise false.

isrootpage
<tt>page → boolean</tt>

Returns true if page is not a subpage, otherwise false.

issubjectpage
<tt>page → boolean</tt>

Returns true if page is not a talk page, otherwise false.

issubpage
<tt>page → boolean</tt>

Returns true if page is a subpage, otherwise false.

istalkpage
<tt>page → booleam</tt>

Returns true if page is a talk page, otherwise false.

lastedit
<tt>page → revision</tt>

Returns most recent revision of page.

namespace
<tt>page → namespace</tt>

Returns page's namespace.

subjectpage
<tt>page → page</tt>

If page is talk page, returns equivalent subject page, otherwise returns page.

talkpage
<tt>page → page</tt>

If page is not talk page, returns equivalent talk page, otherwise returns page.

target
<tt>page → page</tt>

If page is a redirect, returns redirect target.

text
<tt>page → string</tt>

Returns text of current revision to page.

title
<tt>page → string</tt>

Returns page title.

revision
<tt>number → revision</tt>

Returns revision with id given by argument.

author
<tt>revision → user</tt>

Returns author of revision.

change
<tt>revision → number</tt>

Returns difference in size between revision and previous revision to page.

issection
<tt>revision → boolean</tt>

Returns true if revision is section edit, otherwise false.

minor
<tt>revision → boolean</tt>

Returns true if revision is marked as minor, otherwise false.

new
<tt>revision → boolean</tt>

Returns true if revision is first revision to page, otherwise false.

page
<tt>revision → page</tt>

Returns page to which revision was made.

section
<tt>revision → string</tt>

Returns section that was edited, if any.

size
<tt>revision → number</tt>

Returns size of revision.

summary
<tt>revision → string</tt>

Returns edit summary for revision.

time
<tt>revision → date</tt>

Returns revision date/time.

tool
<tt>revision → string</tt>

Returns tool used for revision, if identifiable from summary.

user
<tt>string → user</tt>

Returns user with name given by argument.

anonymous
<tt>user → boolean</tt>

Returns true if user is anonymous, otherwise false.

created
<tt>user → date</tt>

Returns date/time of account creation.

editcount
<tt>user → number</tt>

Returns number of edits user has made.

ignored
<tt>user → boolean</tt>

Returns true if user is on ignored users list, otherwise false.

name
<tt>user → string</tt>

Returns user's name.

talkpage
<tt>user → page</tt>

Returns user's talk page.

userpage
<tt>user → page</tt>

Returns user's user page.

namespace
<tt>number → namespace</tt>

Returns namespace with specified number.

issubjectspace
<tt>namespace → boolean</tt>

Returns true if namespace is not a talk namespace, otherwise false.

istalkspace
<tt>namespace → boolean</tt>

Returns true if namespace is a talk namespace, otherwise false.

name
<tt>namespace → string</tt>

Returns namespace name.

number
<tt>namespace → number</tt>

Returns namespace number.

subpages
<tt>namespace → boolean</tt>

Returns true if subpages are enabled in namespace, otherwise false.

List requests
Optional parameters common to all requests:


 * <tt>cache</tt> (boolean): Set to false to ignore any cached results.
 * <tt>limit</tt> (number): Maximum number of results to return. Default 1000.
 * <tt>namespaces</tt> (number): For requests that return pages or revisions, limit results to specified namespaces.
 * <tt>type</tt> (string): For requests that return pages, specify "revisions" to return info on last revision to each page, and "content" to return full text of last revision to each page.

allpages
<tt>void → list</tt>

Returns all pages.

backlinks
<tt>page → list</tt>

Returns pages that link to specified page.

category
<tt>category → list</tt>

Returns contents of specified category.

contribs
<tt>user → list</tt>

Returns user's contributions.

deletedcontribs
<tt>user → list</tt>

Returns user's deleted contributions.

externallinkusage
<tt>string → list</tt>

Returns pages containing specified external link.

history
<tt>page → list</tt>

Returns revisions of specified page.

images
<tt>page → list</tt>

Returns images on specified page.

imageusage
<tt>page → list</tt>

Returns pages that use specified image.

links
<tt>page → list</tt>

Returns all internal links on specified page.

prefix
<tt>string → list</tt>

Returns pages with titles that begin with specified prefix.

subcats
<tt>category → list</tt>

Returns subcategories of specified category.

search
<tt>string → list</tt>

Returns pages that appear in search results for specified search term.

templates
<tt>page → list</tt>

Returns templates used on specified page.

transclusions
<tt>page → list</tt>

Returns pages on which specified template is used.

pagecount
<tt>void → number</tt>

Returns total number of pages.

articlecount
<tt>void → number</tt>

Returns total number of articles.

usercount
<tt>void → number</tt>

Returns total number of user accounts.

activeusercount
<tt>void → number</tt>

Returns total number of active user accounts.

filecount
<tt>void → number</tt>

Returns total number of files.

editscount
<tt>void → number</tt>

Returns total number of revisions.

expand
<tt>string → string</tt>

Returns argument treated as wiki markup with any templates expanded.

strip
<tt>string → string</tt>

Returns argument with wiki links, tags and formatting removed.

paramnorm
<tt>string → string</tt>

Returns argument normalized according to parameter normalization table.

getparam
<tt>(wikitext:string, template:string, param:string) → string</tt>

Returns value of parameter <tt>param</tt> in first occurence of <tt>template</tt> in <tt>wikitext</tt>.

setparam
<tt>(wikitext:string, template:string, param:string, value:string) → boolean</tt>

Returns <tt>wikitext</tt> with parameter <tt>param</tt> in first occurence of <tt>template</tt> set to <tt>value</tt>. Treats any template that redirects to <tt>template</tt> as an instance of such. Replaces parameter value if it already exists, otherwise adds it. Does nothing if no instance of <tt>template</tt> is found. Returns true if parameter was set, otherwise false.

addcategory
<tt>(wikitext:string, category:string) → string</tt>

Returns <tt>wikitext</tt> with <tt>category</tt> added. Does not add category if already present.

removecategory
<tt>(wikitext:string, category:string) → string</tt>

Returns <tt>wikitext</tt> with <tt>category</tt> removed, or no change if category not present.

replacecategory
<tt>(wikitext:string, category:string, replacement:string) → string</tt>

Returns <tt>wikitext</tt> with <tt>category</tt> replaced with <tt>replacement</tt>, or no change if not present.

removetemplate
<tt>(wikitext:string, template:string) → string</tt>

Returns <tt>wikitext</tt> with first occurence of <tt>template</tt> removed, or no change if no instance of <tt>template</tt> present. Treats any template that redirects to <tt>template</tt> as an instance of such.

edit
<tt>(page:page, wikitext:string, summary:string) → string</tt>

Edits page specified by <tt>page</tt>, using <tt>wikitext</tt> as text and <tt>summary</tt> as edit summary.

Optional arguments:


 * <tt>section</tt> - string. Edit this section. Should be number or "new".
 * <tt>minor</tt> - boolean. Whether to mark as minor edit. Defaults to true.
 * <tt>bot</tt> - boolean. Whether to mark as bot edit. Defaults to true if account is in bot group, has no effect if not.
 * <tt>create</tt> - boolean. Whether to create page if it does not exist. Defaults to true.
 * <tt>conflict</tt> - string. Behaviour in event of edit conflict. One of the following values. Default is <tt>ignore</tt>.
 * <tt>abort</tt> - Give up and move on.
 * <tt>retry</tt> - Try again. When adding section or prepending/appending text, applies changes on top of conflicted edit. Will overwrite conflicted edit in other cases.
 * <tt>prompt</tt> - Ask whether to save anyway.
 * <tt>ignore</tt> - Don't bother checking for conflicts in the first place.