Functions
Output¶
print¶
Description:
Prints the given input. Includes a newline after. Stringifies whatever is given to it.
print(items ...any?)
Parameters:
items: ...any?
: Zero or more items to print. If several are given, they get printed separated by spaces.
Examples:
print("Hello!")
name = "Alice"
print("Hello", name) // prints "Hello Alice"
print() // prints a newline
numbers = [1, 20, 300]
print(numbers) // prints "[1, 20, 300]"
pprint¶
Description:
Pretty prints the given input. Mainly useful for maps so they get printed in a json-style.
pprint(item any?)
Parameters:
input: any?
: Zero or one item to pretty print. If zero, just prints a newline.
Examples:
Example 1
item = { "name": "Alice", age: 30 }
pprint(item)
Example 1 Output
{
"name": "Alice",
"age": 30
}
debug¶
Behaves like print
but only prints if debug is enabled via the --DEBUG
flag.
debug(items ...any?)
Misc¶
exit¶
exit(code int = 0)
sleep¶
sleep(seconds int)
sleep(seconds float)
sleep(duration string)
len¶
len(input string) -> int
len(input any[]) -> int
len(input map) -> int
range¶
range(end int|float) -> int|float[]
range(start int|float, end int|float) -> int|float[]
range(start int|float, end int|float, step int|float) -> int|float[]
range(5) -> [0, 1, 2, 3, 4]
range(5.5) -> [0, 1, 2, 3, 4, 5]
range(0.5, 5) -> [0.5, 1.5, 2.5, 3.5, 4.5]
range(10, 5, -2) -> [10, 8, 6]
confirm¶
confirm() -> bool
confirm(prompt string) -> bool
Example 1
if confirm():
print("Confirmed!")
else:
print("Not confirmed!")
Example 1 Output
Confirm? [y/n] y
Confirmed!
Example 2
if confirm("Are you sure? > "):
print("You're sure!")
else:
print("Unsure!")
Example 2 Output
Are you sure? > n
Unsure!
join¶
join(input any[], joiner string, prefix string|int|float|bool?, suffix string|int|float|bool?) -> string
unique¶
unique(input any[]) -> any[]
unique([2, 1, 2, 3, 1, 3, 4]) // [2, 1, 3, 4]
sort¶
sort(input any[], reverse=bool?)
sort([3, 4, 2, 1]) // [1, 2, 3, 4]
sort([3, 4, 2, 1], reversed=true) // [4, 3, 2, 1]
sort([3, 4, "2", 1, true]) // [true, 1, 3, 4, "2"]
Parsing¶
parse_int¶
parse_int(input str) -> int, err
parse_float¶
parse_float(input str) -> float, err
parse_json¶
parse_json(input string) -> any
Time¶
now_date¶
now_date() -> string // e.g. "2006-11-25"
now_year¶
now_year() -> int // e.g. 2006
now_month¶
now_month() -> int // e.g. 11
now_day¶
now_day() -> int // e.g. 25
now_hour¶
now_hour() -> int // e.g. 14
now_minute¶
now_minute() -> int // e.g. 31
now_second¶
now_second() -> int // e.g. 35
epoch_seconds¶
epoch_seconds() -> int // e.g. 1731063226
epoch_millis¶
epoch_millis() -> int // e.g. 1731063226123
epoch_nanos¶
epoch_nanos() -> int // e.g. 1731063226123456789
Text¶
upper¶
- Preserves string color attributes.
upper(input any) -> string
lower¶
- Preserves string color attributes.
lower(input any) -> string
replace¶
- Does not preserve string color attributes.
Parameters:
input: string
old: string
: Regex pattern of what text to replace.new: string
: Regex pattern of what to replace matches with.
replace(input string, old string, new string) -> string
Examples:
Example 1
input = "Name: Charlie Brown"
replace(input, "Charlie (.*)", "Alice $1")
Example 1 Output
"Alice Brown"
starts_with¶
starts_with(input string, substring string) -> bool
ends_with¶
ends_with(input string, substring string) -> bool
truncate¶
truncate(input string, length int) -> string
split¶
- Does not preserve string color attributes.
split(input string, delimiter_regex string) -> string[]
Maps¶
keys¶
keys(input map) -> any[]
values¶
values(input map) -> any[]
Random¶
rand¶
rand() -> float
rand_int¶
rand_int(max int) -> int
rand_int(min int, max int) -> int
seed_random¶
seed_random(seed int)
Picking¶
pick¶
pick(options string[], filter string?) -> string
Named args:
- prompt
pick_kv¶
pick_kv(keys string[], values string[], filter string?) -> string
Named args:
- prompt
pick_from_resource¶
pick_from_resource(resource_path string, filter string?) -> any...
HTTP¶
Map outputs contain the following keys:
- status_code
- body
Failed queries (e.g. invalid url, no response) will result in an error and script exit.
http_get¶
http_get(url string) -> map
http_get(url string, headers = map) -> map
http_post¶
http_post(url string, body any?) -> map
http_post(url string, body any?, headers = map) -> map
http_put¶
http_put(url string, body any?) -> map
http_put(url string, body any?, headers = map) -> map
Math¶
abs¶
abs(int) -> int
abs(float) -> float