Return to index

conversion functions

big_float = as_bigf(expr)

top

Convert expr to a float. Also ensures this is a copy.

Example:

# Example for as_bigf
println as_bigf("3.14159265358979323846")


big_int = as_bigi(expr)

top

Convert expr to a big integer. Also ensures this is a copy.

Example:

# Example for as_bigi
println as_bigi("12345678901234567890")


bool = as_bool(string)

top

Convert string to a boolean value, or errors

Example:

# Example for as_bool
println as_bool("true")


float = as_float(var)

top

Convert var to a float. Returns NaN on error.

Example:

# Example for as_float
println as_float("3.14159")


integer = as_int(var)

top

Convert var to an integer, or errors.

Example:

# Example for as_int
println as_int("42")


integer = as_int64(var)

top

Convert var to an int64 type, or errors.

Example:

# Example for as_int64
println as_int64("42")


string = as_string(value[,precision])

top

Converts value to a string.

Example:

# Example for as_string
println as_string(42)


unsigned_integer = as_uint(var)

top

Convert var to a uint type, or errors.

Example:

# Example for as_uint
println as_uint("42")


int = asc(string)

top

Return a numeric representation of the first char in string.

Example:

# Example for asc
println asc("A")


string = base64d(string)

top

Return a string of the base64 decoding of string

Example:

# Example for base64d
encoded = base64e("Hello World")
println base64d(encoded)


string = base64e(string)

top

Return a string of the base64 encoding of string

Example:

# Example for base64e
println base64e("Hello World")


int = btoi(bool)

top

Return an int which is either 1 when bool is true or else 0 when bool is false.

Example:

# Example for btoi
println btoi(true)


byte = byte(var)

top

Convert to a uint8 sized integer, or errors.

Example:

# Example for byte
println byte(65)
println byte(97)


string = char(int)

top

Return a string representation of ASCII char int. Representations above 127 are empty.

Example:

# Example for char
println char(42)


string = dtoo(int)

top

Convert decimal int to octal string.

Example:

# Example for dtoo
println dtoo(42)


nil_or_any = f2n(any)

top

Converts false to nil or returns true.

Example:

# Example for f2n
println f2n(true)


string = format_currency(number[,symbol])

top

Format a number as currency with comma separators, 2 decimal places, and optional currency symbol (default $).

Example:

# Example for format_currency
println format_currency(3.14)


[]uint8 = hex_decode(string)

top

Decodes a hex-encoded string and returns the resulting byte array, or an error if the string is not valid hex.

Example:

# Example for hex_decode
println hex_decode("48656c6c6f20576f726c64")


string = hex_encode(string|[]uint8)

top

Returns the hex-encoded representation of a string or byte array.

Example:

# Example for hex_encode
hex = hex_encode("Hello World")
println hex
println hex_decode(hex)


string = human_size(number)

top

Converts a byte count to a human-readable string (B, KB, MB, GB, TB).

Example:

# Example for human_size
println human_size(1024)


bool = is_number(expression)

top

Returns true if expression can evaluate to a numeric value.

Example:

# Example for is_number
println is_number("42")
println is_number("hello")
println is_number("3.14")


bool = itob(int)

top

Return a boolean which is set to true when int is non-zero.

Example:

# Example for itob
println itob(42)


map|array = json_decode(string)

top

Decode a JSON string into a map (objects) or array (JSON arrays).

Example:

# Example for json_decode
println json_decode("{\"a\": 1}")


string = json_encode(any)

top

Convert value to a JSON string.

Example:

# Example for json_encode
println json_encode(map(.a 1, .b 2))


string = json_format(string)

top

Return a formatted JSON representation of string, or an empty string on error.

Example:

# Example for json_format
println json_format("{\"a\":1}")


string = json_query(input_string,query_string[,map_bool])

top

Returns the result of processing input_string using the gojq library.


query_string is a jq-like query to operate with. If map_bool is false (default)


then a string is returned, otherwise an iterable list is returned.

Example:

# Example for json_query
json_query("{\"a\": 1}", ".a")


struct = m2s(map,struct_example)

top

Convert a map to struct following field form of struct_example.

Example:

# Example for m2s
r = sys_resources()
m = s2m(r)
println m2s(m, r)


uint64 = maxuint(var)

top

Represents the maximum possible uint value.

Example:

# Example for maxuint
println maxuint()


ansi_code_string = md2ansi(markdown_string)

top

Converts simple markdown syntax to Za ANSI colour codes.

Example:

# Example for md2ansi
println md2ansi("# Hello")


int = otod(string)

top

Convert octal string to decimal int.

Example:

# Example for otod
println otod("10")


string = pp(map|slice, [max_depth], [indent_string])

top

Pretty print a map or slice with optional indentation, depth limit, and colour-coded section headings.

Example:

# Example for pp
pp(map(.a 1))


bool_success = read_struct(filename,name_of_destination_struct)

top

Read a struct from a file.

Example:

# Example for read_struct
r = sys_resources()
write_struct("/tmp/za_struct.bin", "r")
read_struct("/tmp/za_struct.bin", "r")


map = s2m(struct)

top

Convert a struct to map.

Example:

# Example for s2m
r = sys_resources()
println s2m(r)


string = str(value[,precision])

top

Alias for as_string(). Converts a value to a string.

Example:

# Example for str
println str(42)


string or [][]any = table(data, [options])

top

Convert a slice of maps/structs to a text table, or parse a string to structured data.


Example options: .parse_only false (return [][]any), .has_headers false, .detect_sep true, .separator ",",


.hide ["field1"], .show_only_ordered true, .colours map(.header "[#code1]", .data "[#code2]"),


.table_width 80, .column_widths map(.name 10), .align map(.name "left"), .include_headers true,`


.border_style "ascii", .truncate false, .column_order ["col1", "col2"])

Example:

# Example for table
table("hello")  # usage


typed_value = to_typed(value,type_string)

top

Convert value to the specified type type_string. Supports multi-dimensional arrays like '[][]int', '[][][]string', '[5][3]int', etc.

Example:

# Example for to_typed
println to_typed([1, 2, 3], "[]int")


string = type(var)

top

Alias for kind(). Return a string indicating the type of the variable.

Example:

# Example for type
println type(42)
println type("hello")
println type([1, 2, 3])


string = typeof(var)

top

Alias for kind(). Return a string indicating the type of the variable.

Example:

# Example for typeof
println typeof(42)
println typeof("hello")
println typeof([1, 2, 3])


string = url_decode(string)

top

Returns a URL-decoded version of the input string, or an error if the input is not valid.

Example:

# Example for url_decode
encoded = url_encode("hello world!")
println url_decode(encoded)


string = url_encode(string)

top

Returns a URL-encoded (percent-encoded) version of the input string.

Example:

# Example for url_encode
println url_encode("hello world!")


size = write_struct(filename,name_of_struct)

top

Sends a struct to file. Returns byte size written.

Example:

# Example for write_struct
r = sys_resources()
write_struct("/tmp/za_struct.bin", "r")