Standard Constants / Functions
Refers to constants/functions that are defined in Aiscript from the beginning and can be used anywhere.
They are also called std constants/functions without standard.
Syntax
#Core:v
Represents a standard constant named Core:v
.
@Core:type(v: value): str
Represents a standard function named Core:type
.
It takes one argument of type value (i.e., any type) named v
and returns a value of type str (string type).
List
std
@print(message: str): void
Displays a string on the screen.
@readline(message: str): str
Accepts string input.
:: Core
See List of operators for operator-equivalent functions.
#Core:v
Type: str
Version of AiScript runtime that's currently running.
@Core:type(v: any): str
Get the type name of the value.
@Core:to_str(v: any): str
Obtains a string representing a value.
@Core:range(a: num, b: num): arr<num>
Generates a sequence of numbers starting from a and ending in b.
Increments by 1 when a < b
, decrements by 1 when a > b
.
Returns [a]
when a == b
.
Behavior is not defined when a
and/or b
is non-integer.
@Core:sleep(time: num): void
Wait for the specified time (milliseconds).
@Core:abort(message: str): never
Aborts the execution.
:: Util
@Util:uuid(): str
Generates new UUID.
:: Json
@Json:stringify(v: any): str
Generate JSON string.
@Json:parse<T>(json: str): T
Parse JSON into object. Returns an error type value (name
='not_json'
) if the argument is not parsable as JSON.
@Json:parsable(str: str): bool
Determines if a string can be parsed as JSON. Exists for historical reasons.
:: Date
@Date:now(): num
Returns current date.
@Date:year(date?: num): num
Get the year of the time.
If date is passed, the year corresponding to date,
If not passed, the year of the current time is returned.
@Date:month(date?: num): num
Get the month of the time.
If date is passed, the month corresponding to date,
If not passed, the month of the current time is returned.
@Date:day(date?: num): num
Get the day of the current time.
If date is passed, the day corresponding to date,
If not passed, the day of the current time is returned.
@Date:hour(date?: num): num
Get the hour of the current time.
If date is passed, the time corresponding to date,
If not passed, the current time is returned.
@Date:minute(date?: num): num
Get the minutes of the current time.
If date is passed, the minute corresponding to date,
If not passed, the minute of the current time is returned.
@Date:second(date?: num): num
Get the seconds of the current time.
If date is passed, the second corresponding to date,
If not passed, the second of the current time is returned.
@Date:millisecond(date?: num): num
Get the milliseconds of the current time.
If date is passed, the millisecond corresponding to date,
If not passed, the millisecond of the current time is returned.
@Date:parse(date: str): num
Generates a numeric value representing a date/time from a string that can be interpreted as a date.
Interpretation depends on JavaScript's Date constructor.
If the argument is not interpretable as a date, it returns a value of type error (name
='not_date'
).
@Date:to_iso_str(date?: num, time_offset?: num): str
Returns a string with date in extended notation ISO format.
If date is not passed, the current time is used.
time_offset is the time difference (in minutes) from UTC.
If time_offset is not passed, the local one is used.
:: Math
:: Num
@Num:from_hex(hex: str): num
Return number from a hexadecimal string.
:: Str
#Str:lf
Type: str
Line feed (LF).
@Str:lt(a: str, b: str): num
Returns -1 if a < b, 0 if a == b, or 1 if a > b. Can be used as a comparison function for arr.sort.
@Str:gt(a: str, b: str): num
Returns -1 if a > b, 0 if a == b, or 1 if a < b. Can be used as a comparison function for arr.sort.
@Str:from_codepoint(codepoint: num): str
Generates characters from Unicode codepoints.
codepoint must be greater than or equal to 0 and less than or equal to 10FFFFF16.
@Str:from_unicode_codepoints(codePoints: arr<num>): str
Generates characters from an array of numbers representing a sequence of Unicode code points.
Each element of _codePoints must be greater than or equal to 0 and less than or equal to 10FFFFFF16.
@Str:from_utf8_bytes(bytes: arr<num>): str
Generates characters from an array of numbers representing a UTF-8 byte sequence.
Each element of bytes must be greater than or equal to 0 and less than or equal to 255.
:: Uri
@Uri:encode_full(uri: str): str
Returns a string with uri encoded as a URI. The following characters are not encoded:A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; , / ? : @ & = + $ #
@Uri:encode_component(text: str): str
Returns a string with text encoded as a URI component. The following characters are not encoded:A-Z a-z 0-9 - _ . ! ~ * ' ( )
@Uri:decode_full(encoded_uri: str): str
Returns a string that decodes encoded_uri as an encoded URI.
Escape sequences corresponding to the following characters are not decoded:; , / ? : @ & = + $ #
@Uri:decode_component(encoded_text: str): str
Returns a string that decodes encoded_text as an encoded URI component.
:: Arr
@Arr:create<T>(length: num, initial?: T): arr<T>
Creates an array of length length
.
The array will be filled with initial if given, otherwise with null
.
:: Obj
@Obj:keys(v: obj): arr
@Obj:vals<T>(v: obj<T>): arr<T>
@Obj:kvs(v: obj): arr
Returns an array of object keys, values, and key/value pairs.
@Obj:get<T>(v: obj<T>, key: str): T
@Obj:set<T>(v: obj<T>, key: str, val: T): null
@Obj:has(v: obj, key: str): bool
@Obj:copy<T>(v: obj<T>): obj<T>
Generates the copy of the object.
@Obj:merge<T>(o1: obj<T>, o2: obj<T>): obj<T>
Returns a merged version of the two objects.
@Obj:pick<T>(o: obj<T>, keys: arr<str>): obj<T>
Extracts o
's properties which have keys in keys.
Property is set NULL
when the key is in keys
but not in o
.
:: Error
@Error:create(name: str, info?: any): error
Create error type value.
:: Async
@Async:interval(interval: num, callback: @() => any, immediate?: bool): @() => void
Calls the callback function at the specified period.
Returns a stop function.
@Async:timeout(delay: num, callback: @() => any): @() => void
Calls the callback function after the specified time has elapsed.
Returns a stop function as the return value.