Repository navigation
Wi Standard Method Library Reference
This page mirrors Standard Library Reference, but for Standard Method Library.
| Type | Methods |
|---|---|
string |
bytes, sub, upper, lower, trim, has, indexof, startswith, endswith, isdigit, isalpha, isalnum, compare, replace, split, reverse, repeat, each, select, where, find
|
array |
copy, clear, capacity, count, reverse, reversed, add, has, indexof, remove, removeat, insertat, pop, concat, slice, join, each, select, where, sort, find
|
map |
copy, clear, capacity, count, keys, values, has, getordefault, remove, each, select, where, find
|
Note
Modifying an array or a map from inside a callback (each, select, where, sort, find) is a runtime error.
Note
has, indexof, and remove compare items with ==, so arrays, maps, and objects are matched by reference (use std::equals for structural comparison).
Get the byte representation of a string
Parameters:
-
string str: String
Returns: array of byte values (0-255)
Get a substring
Parameters:
-
string str: String -
real start: Start index, inclusive -
real end: End index, exclusive
Returns: string substring from start to end
Convert a string to uppercase
Parameters:
-
string str: String
Returns: string uppercased str
Note: is not UTF-8 aware (will only work on ASCII, everything else – no op)
Convert a string to lowercase
Parameters:
-
string str: String
Returns: string lowercased str
Note: is not UTF-8 aware (will only work on ASCII, everything else – no op)
Remove leading and trailing whitespace from a string
Parameters:
-
string str: String
Returns: string str with leading and trailing whitespace removed
Check if a string contains a substring
Parameters:
-
string str: String -
string target: Substring to search for
Returns: bool true if str contains target, false otherwise
Get the index of the first occurrence of a substring in a string
Parameters:
-
string str: String -
string target: Substring to search for
Returns: real index of the substring, or -1 if not found
Check if a string starts with a prefix
Parameters:
-
string str: String -
string prefix: Prefix to check for
Returns: bool true if str starts with prefix, false otherwise
Check if a string ends with a suffix
Parameters:
-
string str: String -
string suffix: Suffix to check for
Returns: bool true if str ends with suffix, false otherwise
Check if every character in a string is a digit (0-9).
Returns false for an empty string
Parameters:
-
string str: String
Returns: bool true if every character in str is a digit, false otherwise
Note: is not UTF-8 aware
Check if every character in a string is an alphabetic character (a-z, A-Z).
Returns false for an empty string
Parameters:
-
string str: String
Returns: bool true if every character in str is an alphabetic character, false otherwise
Note: is not UTF-8 aware
Check if every character in a string is alphanumeric (a digit or an alphabetic character).
Returns false for an empty string
Parameters:
-
string str: String
Returns: bool true if every character in str is alphanumeric, false otherwise
Note: is not UTF-8 aware
Check if a string is lexicographically less than another
Parameters:
-
string a: String A -
string b: String B
Returns: bool true if a sorts before b, false otherwise
Replace all occurrences of a substring with another string
Parameters:
-
string str: String -
string old: Substring to replace -
string new: Replacement string
Returns: string new string with every occurrence of old replaced by new
Split a string by a separator
Parameters:
-
string str: String -
string sep: Separator
Returns: array of string parts
Reverse a string
Parameters:
-
string str: String
Returns: string reversed str
Repeat a string a number of times
Parameters:
-
string str: String -
real times: Number of times to repeat
Returns: string new repeated string
Call a function for each character in a string
Parameters:
-
string str: String -
function fn: Function called with(char)for each character
Returns: string the same string
Create a new string by transforming each character with a function
Parameters:
-
string str: String -
function fn: Function called with(char)for each character, its return value is concatenated to the result string, return value must be a string
Returns: string new string of transformed characters
Create a new string containing only the characters for which a function returns a truthy value
Parameters:
-
string str: String -
function fn: Function called with(char)for each character
Returns: string new string for which fn returned truthy
Get the first character for which a function returns a truthy value
Parameters:
-
string str: String -
function fn: Function called with(char)for each character
Returns: string the first matching character, or null if there is none
Create a shallow copy of an array
Parameters:
-
array arr: Array
Returns: array shallow copy of arr
Remove all the items from an array
Parameters:
-
array arr: Array
Returns: array the same array
Get the current item capacity of an array
Parameters:
-
array arr: Array
Returns: real current item capacity of arr
Get the number of the items in an array
Parameters:
-
array arr: Array
Returns: real number of items in arr
Reverse an array
Parameters:
-
array arr: Array
Returns: array the same array, reversed
Get a new array with the items in reverse order
Parameters:
-
array arr: Array
Returns: array new reversed array
Add a value to the end of an array
Parameters:
-
array arr: Array -
any value: Value to add
Returns: array the same array
Check if an array contains a value
Parameters:
-
array arr: Array -
any value: Value to search for
Returns: bool true if arr contains value, false otherwise
Get the index of the first occurrence of a value in an array
Parameters:
-
array arr: Array -
any value: Value to search for
Returns: real index of the value, or -1 if not found
Remove the first occurrence of a value from an array
Parameters:
-
array arr: Array -
any value: Value to remove
Returns: bool true if a value was found and removed, false otherwise
Remove the item at the given index
Parameters:
-
array arr: Array -
real index: Index to remove
Returns: any the removed value
Insert a value into an array at the given index
Parameters:
-
array arr: Array -
real index: Index to insert at (can equal the array's current length, to insert at the end) -
any value: Value to insert
Returns: array the same array
Remove the last item of an array
Parameters:
-
array arr: Array
Returns: any the removed value
Concatenate multiple arrays into a new array
Parameters:
-
array ...arrays: Arrays to concatenate
Returns: array new concatenated array
Get a slice of an array
Parameters:
-
array arr: Array -
real start: Start index, inclusive -
real end: End index, exclusive
Returns: array new array containing the items from start to end
Join array items (converted to strings implicitly) into a single string
Parameters:
-
array arr: Array -
string sep: Separator
Returns: string joined string
Call a function for each item in an array
Parameters:
-
array arr: Array -
function fn: Function called with(item)for each item
Returns: array the same array
Create a new array by transforming each item with a function
Parameters:
-
array arr: Array -
function fn: Function called with(item)for each item, its return value is added to the result array
Returns: array new array of transformed items
Create a new array containing only the items for which a function returns a truthy value
Parameters:
-
array arr: Array -
function fn: Function called with(item)for each item
Returns: array new array of items for which fn returned truthy
Sort an array in place using a comparator function (elements that compare equal may end up in any order)
Parameters:
-
array arr: Array -
function fn: Function called with(a, b)for each comparison, should return truthy ifashould be ordered beforeb
Returns: array the same array, sorted
Get the first item for which a function returns a truthy value
Parameters:
-
array arr: Array -
function fn: Function called with(item)for each item
Returns: any the first matching item, or null if there is none
Create a shallow copy of a map
Parameters:
-
map m: Map
Returns: map shallow copy of m
Remove all the entries from a map
Parameters:
-
map m: Map
Returns: map the same map
Get the current entry capacity of a map
Parameters:
-
map m: Map
Returns: real current entry capacity of m
Get the number of live entries in a map
Parameters:
-
map m: Map
Returns: real number of live entries in m
Get all the keys in a map
Parameters:
-
map m: Map
Returns: array of keys
Get all the values in a map
Parameters:
-
map m: Map
Returns: array of values
Check if a map has a key
Parameters:
-
map m: Map -
any key: Key to check for
Returns: bool true if m has key, false otherwise
Get a value from a map, or a default value if the key is not present
Parameters:
-
map m: Map -
any key: Key to look up -
any default: Value to return if the key is not present
Returns: any value for key, or default if the key is not present
Remove a key from a map
Parameters:
-
map m: Map -
any key: Key to remove
Returns: bool true if key existed and was removed, false otherwise
Call a function for each entry in a map
Parameters:
-
map m: Map -
function fn: Function called with(key, value)for each entry
Returns: map the same map
Create a new map by transforming each key and value with functions
Parameters:
-
map m: Map -
function key_fn: Function called with(key)for each entry, its return value becomes the new key -
function value_fn: Function called with(value)for each entry, its return value becomes the new value
Returns: map new map of transformed entries
Create a new map containing only the entries for which a function returns a truthy value
Parameters:
-
map m: Map -
function fn: Function called with(key, value)for each entry
Returns: map new map of entries for which fn returned truthy
Get the key of the first entry for which a function returns a truthy value
Parameters:
-
map m: Map -
function fn: Function called with(key, value)for each entry
Returns: any the key of the first matching entry, or null if there is none
Try Wi online here! · Found a mistake or a typo? Open an issue!
Wi is licensed under the MIT license.