-
Notifications
You must be signed in to change notification settings - Fork 1
sdk.lua
AES encryption and decryption.
function aes.decrypt(key: string, value: string)
-> decrypted: string
Decrypts a string using AES.
@param key
β The key to use for decryption.
@param value
β The string to decrypt.
@return decrypted
β The decrypted string.
function aes.encrypt(key: string, value: string)
-> encrypted: string
Encrypts a string using AES.
@param key
β The key to use for encryption.
@param value
β The string to encrypt.
@return encrypted
β The encrypted string.
Base64 encoding and decoding.
function base64.decode(value: string, encoding?: userdata)
-> decoded: string
Decodes a base64 string.
@param value
β The base64 string to decode.
@param encoding
β The encoding to use. Defaults to std_encoding
.
@return decoded
β The decoded string.
function base64.encode(value: string, encoding?: userdata)
-> encoded: string
Encodes a string to base64.
@param value
β The string to encode.
@param encoding
β The encoding to use. Defaults to std_encoding
.
@return encoded
β The encoded string.
userdata
The standard raw, unpadded base64 encoding, as defined in RFC 4648.
userdata
The alternate raw, unpadded base64 encoding defined in RFC 4648. It is typically used in URLs and file names.
userdata
The standard base64 encoding, as defined in RFC 4648.
userdata
The alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names.
userdata
Various cryptographic functions.
aes
AES encryption and decryption.
md5
MD5 cryptographic hash function.
sha1
SHA1 cryptographic hash function.
sha256
SHA256 cryptographic hash function.
sha512
SHA-512 cryptographic hash function.
base64
Base64 encoding and decoding.
json
Provides functions for encoding and decoding JSON.
Headless browser
function headless.browser()
-> browser: headless_browser
Creates a new headless browser
@return browser
β headless browser instance
(method) headless_browser:page(url: string)
-> page: headless_page
Visit the page
@param url
β url of the page to visit
(method) headless_element:click()
(method) headless_element:html()
-> html: string
(method) headless_element:input(text: string)
(method) headless_page:element(selector: string)
-> element: headless_element
Get HTML element by CSS selector
@param selector
β CSS selector for the element
@return element
β HTML element
(method) headless_page:html()
-> html: string
(method) headless_page:navigate(url: string)
@param url
β URL to navigate
This library provides functions for parsing HTML and querying it using CSS selectors. It is based on goquery.
function html.parse(html: string)
-> document: html_document
Parses the given HTML and returns a selection containing the root element.
@param html
β The HTML to parse.
@return document
β The document object.
Document represents an HTML document to be manipulated. Unlike jQuery, which is loaded as part of a DOM document, and thus acts upon its containing document, GoQuery doesn't know which HTML document to act upon. So it needs to be told, and that's what the document class is for. It holds the root document node to manipulate, and can make selections on this document.
(method) html_document:find(selector: string)
-> selection: html_selection
Finds all elements that match the selector string. It returns a new selection object with the matched elements.
@param selector
β The CSS selector to use to find the elements.
@return selection
β A selection object.
(method) html_document:html()
-> html: string
Gets the HTML contents of the first element in the set of matched elements. It includes text and comment nodes.
@return html
β The HTML contents of the first element in the set of matched elements.
(method) html_document:markdown()
-> markdown: string
Converts the document to Markdown. Can be used to show the contents of a document in info page
@return markdown
β The Markdown representation of the document.
(method) html_document:selection()
-> selection: html_selection
Converts document to a selection object.
@return selection
β A selection object.
(method) html_document:simplified()
-> html: html_document
Gets the readable part of the document (simplified view). Similar to reader mode in browsers.
@return html
β The simplified document
(method) html_selection:add(selector: string)
-> selection: html_selection
Add adds the selector string's matching nodes to those in the current selection and returns a new selection object. The selector string is run in the context of the document of the current selection object.
@param selector
β The CSS selector to use to find the elements.
@return selection
β A selection object.
(method) html_selection:add_back(selection: html_selection)
-> selection: html_selection
Adds the specified Selection object's nodes to those in the current selection and returns a new Selection object.
@param selection
β A selection object.
@return selection
β A selection object.
(method) html_selection:add_class(class: string)
Adds the specified class(es) to each of the set of matched elements.
@param class
β One or more class names to be added to the class attribute of each matched element.
(method) html_selection:add_selection(selection: html_selection)
-> selection: html_selection
Adds the specified selection object's nodes to those in the current selection and returns a new selection object.
@param selection
β A selection object.
@return selection
β A selection object.
(method) html_selection:attr(name: string)
-> value: string
2. ok: boolean
Returns the value of the given attribute of the first element in the selection.
@param name
β The name of the attribute to get.
@return value
β The value of the attribute, or nil if the attribute is not present.
@return ok
β Whether the attribute was present.
(method) html_selection:attr_or(name: string, default: string)
-> value: string
Returns the value of the given attribute of the first element in the selection, or a default value if the attribute is not present.
@param name
β The name of the attribute to get.
@param default
β The default value to return if the attribute is not present.
@return value
β The value of the attribute, or the default value if the attribute is absent.
(method) html_selection:children()
-> selection: html_selection
Gets all direct child elements of each element in the Selection. It returns a new selection object containing the matched elements.
@return selection
β A selection object.
(method) html_selection:closest(selector: string)
-> selection: html_selection
Gets the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
@param selector
β The CSS selector to use to find the elements.
@return selection
β A selection object.
(method) html_selection:contents()
-> selection: html_selection
Contents gets the children of each element in the selection, including text and comment nodes. It returns a new selection object containing these elements
@return selection
β A selection object.
(method) html_selection:each(fn: fun(selection: html_selection, index: number))
Iterates over all elements in the selection, calling the given function for each one.
@param fn
β The function to call for each element.
(method) html_selection:eq(index: number)
-> selection: html_selection
Reduces the set of matched elements to the one at the specified index. If a negative index is given, it counts backwards starting at the end of the set. It returns a new Selection object, and an empty Selection object if the index is invalid.
@param index
β The index of the element to select.
@return selection
β A selection object.
(method) html_selection:filter(selector: string)
-> selection: html_selection
Filter reduces the set of matched elements to those that match the selector string. It returns a new Selection object for this subset of matching elements.
@param selector
β The CSS selector to use to find the elements.
@return selection
β A selection object.
(method) html_selection:find(selector: string)
-> selection: html_selection
Finds all elements matching the given selector.
@param selector
β The CSS selector to use to find the elements.
@return selection
β A selection object.
(method) html_selection:find_selection(selection: html_selection)
-> selection: html_selection
gets the descendants of each element in the current selection, filtered by a selection. It returns a new selection object containing these matched elements.
@param selection
β A selection object.
@return selection
β A selection object.
(method) html_selection:first()
-> selection: html_selection
Reduces the set of matched elements to the first in the set. It returns a new selection object, and an empty selection object if the the selection is empty.
@return selection
β A selection object.
(method) html_selection:has_class(class: string)
-> ok: boolean
determines whether any of the matched elements are assigned the given class.
@param class
β The class to check for.
@return ok
β Whether any of the matched elements have the given class.
(method) html_selection:html()
-> html: string
Returns the HTML contents of the first element in the selection.
@return html
β Gets the HTML contents of the first element in the set of matched elements. It includes text and comment nodes.
(method) html_selection:is(selector: string)
-> ok: boolean
Checks the current matched set of elements against a selector and returns true if at least one of these elements matches.
@param selector
β The CSS selector to use to find the elements.
@return ok
β Whether any of the matched elements match the selector.
(method) html_selection:last()
-> selection: html_selection
Reduces the set of matched elements to the last in the set. It returns a new selection object, and an empty selection object if the the selection is empty.
@return selection
β A selection object.
(method) html_selection:length()
-> n: number
Returns the number of elements in the selection.
@return n
β The number of elements in the selection.
(method) html_selection:map(fn: fun(selection: html_selection, index: number):any)
-> results: any[]
Iterates over a selection, executing a function for each matched element. The function's return value is added to the returned table.
@param fn
β The function to execute for each element. It receives the index of the element in the selection and the element as arguments.
@return results
β A table containing the return values of the function for each element.
(method) html_selection:markdown()
-> markdown: string
Converts the selection to Markdown. Can be used to show the contents of a selection in info page
@return markdown
β The Markdown representation of the selection.
(method) html_selection:next()
-> selection: html_selection
Gets the immediately following sibling of each element in the set of matched elements, optionally filtered by a selector. It returns a new Selection object containing the matched elements.
@return selection
β A selection object.
(method) html_selection:next_all()
Gets all the following siblings of each element in the Selection. It returns a new Selection object containing the matched elements.
(method) html_selection:next_until(selector: string)
-> selection: html_selection
gets all following siblings of each element up to but not including the element matched by the selector. It returns a new Selection object containing the matched elements.
@param selector
β The CSS selector to use to find the elements.
@return selection
β A selection object.
(method) html_selection:parent()
-> selection: html_selection
Gets the parent of each element in the Selection. It returns a new Selection object containing the matched elements.
@return selection
β A selection object.
(method) html_selection:parents()
-> selection: html_selection
Gets the ancestors of each element in the current Selection. It returns a new Selection object with the matched elements.
@return selection
β A selection object.
(method) html_selection:parents_until(selector: string)
-> selection: html_selection
Gets the ancestors of each element in the current Selection, up to but not including the element matched by the selector. It returns a new Selection object with the matched elements.
@param selector
β The CSS selector to use to find the elements.
@return selection
β A selection object.
(method) html_selection:prev()
-> selection: html_selection
Gets the immediately preceding sibling of each element in the Selection. It returns a new selection object containing the matched elements.
@return selection
β A selection object.
(method) html_selection:prev_all()
-> selection: html_selection
Gets all the preceding siblings of each element in the Selection. It returns a new selection object containing the matched elements.
@return selection
β A selection object.
(method) html_selection:prev_until(selector: string)
-> selection: html_selection
Gets all preceding siblings of each element up to but not including the element matched by the selector. It returns a new selection object containing the matched elements.
@param selector
β The CSS selector to use to find the elements.
@return selection
β A selection object.
(method) html_selection:remove(selector: string)
-> selection: html_selection
Removes elements from the selection that match the selector string. It returns a new selection object with the matching elements removed.
@param selector
β The CSS selector to use to find the elements.
@return selection
β A selection object.
(method) html_selection:remove_class(class: string)
Removes the given class(es) from each element in the set of matched elements. Multiple class names can be specified, separated by a space or via multiple arguments. If no class name is provided, all classes are removed.
@param class
β The class to remove. If not provided, all classes are removed.
(method) html_selection:siblings()
-> selection: html_selection
Gets all sibling elements of each element in the Selection. It returns a new selection object containing the matched elements.
@return selection
β A selection object.
(method) html_selection:simplified()
-> selection: html_selection
Gets the readable part of the selection (simplified view). Similar to reader mode in browsers.
@return selection
β A selection object.
(method) html_selection:slice(start: number, finish: number)
-> selection: html_selection
Returns a selection containing a subset of the elements in the original selection. It returns a new selection object with the matched elements.
@param start
β The index of the first element to include in the new selection.
@param finish
β The index of the first element to exclude from the new selection.
@return selection
β A selection object.
(method) html_selection:terminate()
-> selection: html_selection
Ends the most recent filtering operation in the current chain and returns the set of matched elements to its previous state.
@return selection
β A selection object.
(method) html_selection:text()
-> text: string
Returns the text contents of the first element in the selection.
@return text
β The text contents of the first element in the selection.
(method) html_selection:toggle_class(class: string)
Adds or removes the given class(es) for each element in the set of matched elements. Multiple class names can be specified, separated by a space or via multiple arguments.
@param class
β The class to toggle.
Package http provides HTTP client implementations. Make HTTP (or HTTPS) requests
string
CONNECT HTTP Method
string
DELETE HTTP Method
string
GET HTTP Method
string
HEAD HTTP Method
string
PATCH HTTP Method
string
POST HTTP Method
string
PUT HTTP Method
number
Returned if the request was successful
function http.request(method: 'CONNECT'|'DELETE'|'GET'|'HEAD'|'PATCH'...(+2), url: string, body?: string)
-> request: http_request
Create a new HTTP request
@param method
β HTTP method
@param url
β URL
@param body
β Request body
@return request
β Request
method:
| 'GET'
| 'HEAD'
| 'POST'
| 'PUT'
| 'PATCH'
| 'DELETE'
| 'CONNECT'
HTTP Request
(method) http_request:content_length(length?: number)
-> length: number?
Get or set request content length
@param length
β Content length
@return length
β Content length
(method) http_request:cookie(key: string, value?: string)
-> value: string?
Get or set request cookie
@param key
β Cookie key
@param value
β Cookie value
@return value
β Cookie value
(method) http_request:header(key: string, value?: string)
-> value: string?
Get or set request header
@param key
β Header key
@param value
β Header value
@return value
β Header value
(method) http_request:send()
-> response: http_response
Perform request
@return response
β Response
HTTP Response
(method) http_response:body()
-> body: string
Get response body
@return body
β Body
(method) http_response:content_length()
-> length: number
Get response content length
@return length
β Content length
(method) http_response:cookies()
-> cookies: { name: string, value: string }[]
Get response cookies. Returns a list of cookies.
@return cookies
β Cookies
(method) http_response:header(key: string)
-> value: string
Get response header
@param key
β Header key
@return value
β Header value
(method) http_response:status()
-> status: number
Get response status
@return status
β Status
JavaScript execution.
function js.vm()
-> vm: js_vm
Creates a new JavaScript virtual machine.
@return vm
β The new JavaScript virtual machine.
A JavaScript virtual machine. This is used to execute JavaScript code.
(method) js_vm:get(name: string)
-> value: js_vm_value
Gets the value of the given property on the global object.
@param name
β The name of the property.
@return value
β The value of the property.
(method) js_vm:run(code: string)
-> value: js_vm_value
Runs the given JavaScript code.
@param code
β The JavaScript code to run.
@return value
β The value returned by the code.
(method) js_vm:set(name: string, value: any)
Sets the value of the given property on the global object. It will convert the given Lua value to a JavaScript value.
@param name
β The name of the property.
@param value
β The value to set.
A value returned from a JavaScript VM.
(method) js_vm_value:export()
-> value: any
Exports the value to a Lua value.
@return value
β The exported value.
(method) js_vm_value:is_boolean()
-> ok: boolean
Returns whether the value is a boolean.
@return ok
β Whether the value is a boolean.
(method) js_vm_value:is_function()
-> ok: boolean
Returns whether the value is a function.
@return ok
β Whether the value is a function.
(method) js_vm_value:is_nan()
-> ok: boolean
Returns whether the value is NaN.
@return ok
β Whether the value is NaN.
(method) js_vm_value:is_null()
-> ok: boolean
Returns whether the value is null.
@return ok
β Whether the value is null.
(method) js_vm_value:is_number()
-> ok: boolean
Returns whether the value is a number.
@return ok
β Whether the value is a number.
(method) js_vm_value:is_object()
-> ok: boolean
Returns whether the value is an object.
@return ok
β Whether the value is an object.
(method) js_vm_value:is_string()
-> ok: boolean
Returns whether the value is a string.
@return ok
β Whether the value is a string.
(method) js_vm_value:is_undefined()
-> ok: boolean
Returns whether the value is undefined.
@return ok
β Whether the value is undefined.
(method) js_vm_value:to_string()
-> string: string
Converts the value to a string.
@return string
β The string representation of the value.
Provides functions for encoding and decoding JSON.
function json.decode(json: string)
-> value: any
Decodes a JSON string into a Lua value.
@param json
β The JSON string to decode.
@return value
β The decoded value.
function json.encode(value: any)
-> json: string
Encodes a Lua value into a JSON string.
@param value
β The value to encode.
@return json
β The encoded JSON string.
Levenshtein distance algorithm
function levenshtein.distance(s1: string, s2: string)
-> distance: number
Compute Levenshtein distance between two strings
@return distance
β Levenshtein distance between s1 and s2
MD5 cryptographic hash function.
function md5.sum(value: string)
-> hash: string
Returns the MD5 hash of the given string.
@param value
β The string to hash.
@return hash
β The MD5 hash of the given string.
Compiled regular expression
(method) re:find_submatch(text: string)
-> matches: table
Returns a slice of strings holding the text of the leftmost match of the regular expression in s and the matches, if any, of its subexpressions. A return value of empty table indicates no match.
@param text
β A string to search in
@return matches
β Found matches
(method) re:groups(text: string)
-> groups: table
Returns a table of all capture groups.
@param text
β The text to split
@return groups
β A table of all capture groups
(method) re:match(text: string)
-> matched: table
Reports whether the string s contains any match of the regular expression.
@param text
β A string to search in
@return matched
β Whether the string s contains any match of the regular expression.
(method) re:replace_all(text: string, replacement: string)
-> replaced: string
Returns a copy of text, replacing matches of the regexp with the replacement string. Inside replacement, $ signs are interpreted as in expand, so for instance $1 represents the text of the first submatch.
@param text
β A string to replace matches in
@param replacement
β A string to replace matches with
@return replaced
β The result of the replacement
(method) re:replace_all_func(text: string, replacer: fun(match: string):string)
-> replaced: string
Returns a copy of text, replacing matches of the regexp with the replacement function.
@param text
β A string to replace matches in
@param replacer
β A function to replace matches with
@return replaced
β The result of the replacement
(method) re:split(text: string)
-> parts: table
Splits the given text into a table of strings.
@param text
β The text to split
@return parts
β The result of the split
A regular expression library.
function regexp.compile(pattern: string)
-> regexp: re
Compiles the given pattern into a regular expression.
@param pattern
β The pattern to compile
@return regexp
β The compiled regular expression
function regexp.match(pattern: string, text: string)
-> matched: table
Matches the given pattern against the given text.
@param pattern
β The pattern to match
@param text
β The text to match against
@return matched
β A table of all matches
userdata
Matches all the urls it can find.
userdata
Only matches urls with a scheme to avoid false positives.
Contains various utilities for making HTTP requests, working with JSON, HTML, and more.
crypto
Various cryptographic functions.
encoding
headless
Headless browser
html
This library provides functions for parsing HTML and querying it using CSS selectors. It is based on goquery.
http
Package http provides HTTP client implementations. Make HTTP (or HTTPS) requests
js
JavaScript execution.
levenshtein
Levenshtein distance algorithm
regexp
A regular expression library.
strings
Simple functions to manipulate UTF-8 encoded strings.
time
Time library
urls
URLs is a library for working with URLs.
util
Functional helpers
SHA1 cryptographic hash function.
function sha1.sum(value: string)
-> hash: string
Returns the SHA1 hash of the given string.
@param value
β The string to hash.
@return hash
β The SHA1 hash of the given string.
SHA256 cryptographic hash function.
function sha256.sum(value: string)
-> hash: string
Returns the SHA256 hash of the given string.
@param value
β The string to hash.
@return hash
β The SHA256 hash of the given string.
SHA-512 cryptographic hash function.
function sha512.sum(value: string)
-> hash: string
Returns the SHA-512 hash of the given string.
@param value
β The string to hash.
@return hash
β The SHA-512 hash of the given string.
Simple functions to manipulate UTF-8 encoded strings.
function strings.contains(s: string, substr: string)
-> ok: boolean
Returns true if the string s contains substr.
@param s
β The string to check.
@param substr
β The substring to check for.
@return ok
β True if the string contains the substring.
function strings.contains_any(s: string, chars: string)
-> ok: boolean
Returns true if the string s contains any of the runes in chars. If chars is the empty string, contains_any returns false.
@param s
β The string to check.
@param chars
β The characters to check for.
@return ok
β True if the string contains any of the characters.
function strings.count(s: string, substr: string)
-> n: number
Returns the number of non-overlapping instances of substr in s.
@param s
β The string to check.
@param substr
β The substring to check for.
@return n
β The number of non-overlapping instances of substr in s.
function strings.count_any(s: string, chars: string)
-> n: number
Returns the number of non-overlapping instances of any of the runes in chars in s.
@param s
β The string to check.
@param chars
β The characters to check for.
@return n
β The number of non-overlapping instances of any of the runes in chars in s.
function strings.duplicate(s: string, count: number)
-> s: string
Returns a new string consisting of count copies of the string s. If count is zero or negative, returns the empty string.
@param s
β The string to repeat.
@param count
β The number of times to repeat the string.
@return s
β A new string consisting of count copies of the string s.
function strings.equal_fold(s: string, t: string)
-> ok: boolean
Returns true if the strings s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding.
@param s
β The first string to check.
@param t
β The second string to check.
@return ok
β True if the strings are equal under Unicode case-folding.
function strings.has_prefix(s: string, prefix: string)
-> ok: boolean
Returns true if the string s begins with prefix.
@param s
β The string to check.
@param prefix
β The prefix to check for.
@return ok
β True if the string has the prefix.
function strings.has_suffix(s: string, suffix: string)
-> ok: boolean
Returns true if the string s ends with suffix.
@param s
β The string to check.
@param suffix
β The suffix to check for.
@return ok
β True if the string has the suffix.
function strings.index(s: string, substr: string)
-> i: number
Returns the index of the first instance of substr in s, or -1 if substr is not present in s.
@param s
β The string to check.
@param substr
β The substring to check for.
@return i
β The index of the first instance of substr in s, or -1 if substr is not present in s.
function strings.index_any(s: string, chars: string)
-> i: number
Returns the index of the first instance of any of the runes in chars in s, or -1 if none of the runes in chars are present in s.
@param s
β The string to check.
@param chars
β The characters to check for.
@return i
β The index of the first instance of any of the runes in chars in s, or -1 if none of the runes in chars are present in s.
function strings.last_index(s: string, substr: string)
-> i: number
Returns the index of the last instance of substr in s, or -1 if substr is not present in s.
@param s
β The string to check.
@param substr
β The substring to check for.
@return i
β The index of the last instance of substr in s, or -1 if substr is not present in s.
function strings.last_index_any(s: string, chars: string)
-> i: number
Returns the index of the last instance of any of the runes in chars in s, or -1 if none of the runes in chars are present in s.
@param s
β The string to check.
@param chars
β The characters to check for.
@return i
β The index of the last instance of any of the runes in chars in s, or -1 if none of the runes in chars are present in s.
function strings.replace(s: string, old: string, new: string, n: number)
-> new: string
Replaces the first n instances of old with new in s.
@param s
β The string to replace in.
@param old
β The string to replace.
@param new
β The string to replace with.
@param n
β The number of instances to replace.
@return new
β The new string.
function strings.replace_all(s: string, old: string, new: string)
-> new: string
Replaces all instances of old with new in s.
@param s
β The string to replace in.
@param old
β The string to replace.
@param new
β The string to replace with.
@return new
β The new string.
function strings.split(s: string, sep: string)
-> table: table
Splits s around each instance of sep and returns a table of the substrings between those instances.
@param s
β The string to split.
@param sep
β The string to split around.
@return table
β A table of the substrings between each instance of sep.
function strings.title(s: string)
-> s: string
Returns a copy of the string s with all Unicode letters that begin words mapped to their title case.
@param s
β The string to convert.
@return s
β A copy of the string s with all Unicode letters that begin words mapped to their title case.
function strings.to_lower(s: string)
-> new: string
Returns a copy of the string s with all Unicode letters mapped to their lower case.
@param s
β The string to convert.
@return new
β The new string.
function strings.to_upper(s: string)
-> new: string
Returns a copy of the string s with all Unicode letters mapped to their upper case.
@param s
β The string to convert.
@return new
β The new string.
function strings.trim(s: string, cutset: string)
-> new: string
Returns a copy of the string s with all leading and trailing Unicode code points contained in cutset removed.
@param s
β The string to trim.
@param cutset
β The set of Unicode code points to remove.
@return new
β The new string.
function strings.trim_left(s: string, cutset: string)
-> new: string
Returns a copy of the string s with all leading Unicode code points contained in cutset removed.
@param s
β The string to trim.
@param cutset
β The set of Unicode code points to remove.
@return new
β The new string.
function strings.trim_prefix(s: string, prefix: string)
-> new: string
Returns a copy of the string s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
@param s
β The string to trim.
@param prefix
β The prefix to remove.
@return new
β The new string.
function strings.trim_right(s: string, cutset: string)
-> new: string
Returns a copy of the string s with all trailing Unicode code points contained in cutset removed.
@param s
β The string to trim.
@param cutset
β The set of Unicode code points to remove.
@return new
β The new string.
function strings.trim_space(s: string)
-> new: string
Returns a copy of the string s with all leading and trailing white space removed, as defined by Unicode.
@param s
β The string to trim.
@return new
β The new string.
function strings.trim_suffix(s: string, suffix: string)
-> new: string
Returns a copy of the string s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.
@param s
β The string to trim.
@param suffix
β The suffix to remove.
@return new
β The new string.
Time library
number
Duration constant. 60 * minute
number
Duration constant. 1000 * nanosecond
number
Duration constant. 1000 * microsecond
number
Duration constant. 60 * second
number
Duration constant
number
Duration constant. 1000 * millisecond
function time.sleep(duration: number)
Sleep for the given duration
URLs is a library for working with URLs.
function urls.parse(raw_url: string)
-> url: urls_url
Parses URL
@param raw_url
β URL string to parse
@return url
β Parsed URL
function urls.path_escape(path: string)
-> escaped: string
Escapes the string so it can be safely placed inside a URL path segment, replacing special characters (including /) with %XX sequences as needed.
@param path
β The path to escape.
@return escaped
β The escaped path.
function urls.path_unescape(escaped: string)
-> path: string
Unescapes a string; the inverse operation of path_escape. It converts each 3-byte encoded substring of the form "%AB" into the hex-decoded byte 0xAB.
@param escaped
β The escaped path.
@return path
β The unescaped path.
function urls.query_escape(query: string)
-> escaped: string
Escapes the string so it can be safely placed inside a URL query parameter, replacing special characters (including /) with %XX sequences as needed.
@param query
β The query to escape.
@return escaped
β The escaped query.
function urls.query_unescape(escaped: string)
-> query: string
Unescapes a string; the inverse operation of query_escape. It converts each 3-byte encoded substring of the form "%AB" into the hex-decoded byte 0xAB.
@param escaped
β The escaped query.
@return query
β The unescaped query.
function urls.values()
-> values: urls_values
Creates a new values.
@return values
β The new values.
Structured URL
(method) urls_url:copy()
-> url: urls_url
Copy URL
@return url
β A copied URL
(method) urls_url:hostname()
-> hostname: string
Return hostname without port numbers.
@return hostname
β URLs hostname
(method) urls_url:join_path(...string)
-> url: urls_url
Returns a new URL with the provided path elements joined to any existing path and the resulting path cleaned of any ./ or ../ elements. Any sequences of multiple / characters will be reduced to a single /.
(method) urls_url:parse(ref: string)
-> url: urls_url
Parses a URL in the context of the receiver. The provided URL may be relative or absolute.
(method) urls_url:query(query?: urls_values)
-> query: urls_values?
(method) urls_url:string()
-> url: string
Reassembles the URL into a valid URL string.
Values maps a string key to a list of values. It is typically used for query parameters and form values. Unlike in the http.header
map, the keys in a values
map are case-sensitive.
(method) urls_values:add(key: string, value: string)
Adds the key and value to the values. It appends to any existing values associated with key.
@param key
β The key to add. It must not be empty.
@param value
β The value to add. It must not be empty.
(method) urls_values:del(key: string)
Deletes the values associated with key.
@param key
β The key to delete.
(method) urls_values:get(key: string)
-> value: string
Gets the first value associated with the given key. If there are no values associated with the key, Get returns "".
@param key
β The key to get.
@return value
β The first value associated with the given key.
(method) urls_values:has(key: string)
-> has: boolean
Returns true if the values contains the specified key, false otherwise.
@param key
β The key to check.
@return has
β True if the values contains the specified key, false otherwise.
(method) urls_values:parse(encoded: string)
-> values: urls_values
Creates a values from the URL encoded form. It is the inverse operation of string.
@param encoded
β The URL encoded form of the values.
@return values
β The values created from the URL encoded form.
(method) urls_values:set(key: string, value: string)
Sets the key to value. It replaces any existing values associated with key.
@param key
β The key to add. It must not be empty.
@param value
β The value to add. It must not be empty.
(method) urls_values:string()
-> encoded: string
Encodes the values into "URL encoded" form sorted by key.
@return encoded
β The URL encoded form of the values.
Functional helpers
function util.chunk(list: <T>[], size?: number)
-> chunks: <T>[][]
Split list into chunks
@param list
β List to split
@param size
β Chunk size
@return chunks
β List of chunks
function util.contains_by(list: <T>[], predicate: fun(value: <T>):boolean)
-> contains: boolean
Checks if a list contains a value using predicate
@param list
β List to check
@param predicate
β Predicate function
@return contains
β Whether the list contains the value
function util.drop(list: <T>[], n: number)
-> dropped: <T>[]
Drop n elements from the beginning list
@param list
β List to drop from
@param n
β Number of elements to drop
@return dropped
β List of dropped elements
function util.drop_right(list: <T>[], n: number)
-> dropped: <T>[]
Drop n elements from the end of list
@param list
β List to drop from
@param n
β Number of elements to drop
@return dropped
β List of dropped elements
function util.drop_right_while(list: <T>[], predicate: fun(value: <T>):boolean)
Drop elements from the end of list while predicate is true
@param list
β List to drop from
@param predicate
β Predicate function
function util.drop_while(list: <T>[], predicate: fun(value: <T>):boolean)
Drop elements from the beginning of list while predicate is true
@param list
β List to drop from
@param predicate
β Predicate function
function util.filter(list: <T>[], predicate: fun(value: <T>, index: number):boolean)
-> filtered: <T>[]
Filter list by predicate
@param list
β List to filter
@param predicate
β Predicate function
@return filtered
β List of filtered elements
function util.find(list: <T>[], predicate: fun(value: <T>):boolean)
-> element: <T>
2. ok: boolean
Find first element in list that satisfies predicate.
@param list
β List to search
@param predicate
β Predicate function
@return element
β First element that satisfies predicate
@return ok
β True if element was found
function util.find_index(list: <T>[], predicate: fun(value: <T>):boolean)
-> index: number
2. ok: boolean
Find index of first element in list that satisfies predicate.
@param list
β List to search
@param predicate
β Predicate function
@return index
β Index of first element that satisfies predicate
@return ok
β True if element was found
function util.find_last_index(list: <T>[], predicate: fun(value: <T>):boolean)
-> index: number
2. ok: boolean
Find index of last element in list that satisfies predicate.
@param list
β List to search
@param predicate
β Predicate function
@return index
β Index of last element that satisfies predicate
@return ok
β True if element was found
function util.for_each(list: <T>[], func: fun(value: <T>, index: number))
Calls a function for each element in a list
@param list
β List to iterate over
@param func
β Function to call
function util.head(list: <T>[])
-> element: <T>?
Get first element of list
@param list
β List to get first element from
@return element
β First element of list
function util.id(value: <T>)
-> result: <T>
Returns the first argument
@param value
β Value to return
@return result
β The first argument
function util.init(list: <T>[])
-> initial: <T>[]?
Get all elements of list except last
@param list
β List to get initial from
@return initial
β List of all elements except last
function util.last(list: <T>[])
-> element: <T>?
Get last element of list
@param list
β List to get last element from
@return element
β Last element of list
function util.map(table: table<<T>, <G>>, func: fun(value: <G>, key: <T>):<Q>)
-> mapped: table<<T>, <Q>>
Maps a function over a table values
@param table
β Table to map over
@param func
β Mapping function
@return mapped
β Mapped list
function util.map_async(table: table<<T>, <G>>, func: fun(value: <G>, key: <T>):<Q>)
-> mapped: table<<T>, <Q>>
Maps a function over a table values asynchronously
@param table
β Table to map values over
@param func
β Mapping function. Takes a value of each key
@return mapped
β Mapped table
function util.max_by(list: <T>[], func: fun(a: <T>, b: <T>):boolean)
-> result: <T>
Returns the maximum value of a list, based on a function
@param list
β List to find the maximum value of
@param func
β Function to use to compare values. Returns true if the first argument is less than the second
@return result
β The maximum value
function util.min_by(list: <T>[], func: fun(a: <T>, b: <T>):boolean)
-> result: <T>
Returns the minimum value of a list, based on a function
@param list
β List to find the minimum value of
@param func
β Function to use to compare values. Returns true if the first argument is less than the second
@return result
β The minimum value
function util.reduce(list: <T>[], func: fun(accumulator: <G>, value: <T>, index: number):<G>, inital: <G>)
-> result: <G>
Reduces a list to a single value
@param list
β List to reduce
@param func
β Function to reduce with
@param inital
β An initial value
@return result
β Result of the reduction
function util.reduce_right(list: <T>[], func: fun(accumulator: <G>, value: <T>, index: number):<G>, initial: <G>)
-> result: <G>
Reduces a list to a single value
@param list
β List to reduce
@param func
β Function to reduce with
@param initial
β An initial value
@return result
β Result of the reduction
function util.reject(list: <T>[], predicate: fun(value: <T>, index: number):boolean)
-> result: <T>[]
Rejects all elements that match a predicate
@param list
β List to reject from
@param predicate
β Predicate function
@return result
β List of rejected elements
function util.reverse(list: <T>[])
-> reversed: <T>[]
Reverse list
@param list
β List to reverse
@return reversed
β Reversed list
function util.slice(list: <T>[], start: number, finish?: number)
-> slice: <T>[]
Get slice of list
@param list
β List to get slice from
@param start
β Start index of slice
@param finish
β End index of slice. Defaults to length of list
@return slice
β Slice of list
function util.sort(list: <T>[], cmp: fun(a: <T>, b: <T>):boolean)
-> sorted: <T>[]
Returns a sorted list
@param list
β List to sort
@param cmp
β Comparison function. Defaults to <
@return sorted
β Sorted list
function util.tail(list: <T>[])
-> tail: <T>[]?
Get all elements of list except first
@param list
β List to get tail from
@return tail
β List of all elements except first
function util.take(list: <T>[], n: number)
-> elements: <T>[]?
Get first n elements of list
@param list
β List to get elements from
@param n
β Number of elements to get
@return elements
β First n elements of list
function util.take_while(list: <T>[], predicate: fun(value: <T>):boolean)
-> elements: <T>[]?
Take elements from list while predicate is true
@param list
β List to get elements from
@param predicate
β Predicate function
@return elements
β Elements of list before predicate is false