Convert Library Reference
The convert
library provides functions for converting values between types and checking their types at runtime. You must import the convert
module to use these functions; calling them directly on values (e.g. x.toint()
) is not supported.
To use:
import convert
or for specific functions:
from convert import toint, typeof
Available Functions
Function | Parameters | Description |
---|---|---|
toint(x) | x (any) | Converts x to an integer (truncates floats, parses strings, converts bools). |
todouble(x) | x (any) | Converts x to a double (parses strings, converts bools). |
tostring(x) | x (any) | Converts any x to its string representation. |
isint(x) | x (any) | Returns true if x is a whole number (no fractional part). |
isalnum(x) | x (String) | Returns true if every character in x is alphanumeric. |
isdigit(x) | x (String) | Returns true if every character in x is a digit (0–9). |
isdouble(x) | x (any) | Returns true if x is a number with a fractional part. |
isstring(x) | x (any) | Returns true if x is a string. |
islist(x) | x (any) | Returns true if x is a list/array. |
isdict(x) | x (any) | Returns true if x is a dictionary. |
typeof(x) | x (any) | Returns the type of x as a string: "number" , "string" , "bool" , "list" , "dict" , "function" , or "null" . |
Examples
All examples require importing the module first:
import convert
toint(x)
set a to convert.toint(3.8)
show(a)
// Output:
// 3
set b to convert.toint("42")
show(b)
// Output:
// 42
set c to convert.toint(false)
show(c)
// Output:
// 0
todouble(x)
set d1 to convert.todouble(5)
show(d1)
// Output:
// 5
set d2 to convert.todouble("3.14")
show(d2)
// Output:
// 3.14
set d3 to convert.todouble(true)
show(d3)
// Output:
// 1
tostring(x)
set s1 to convert.tostring(123)
show(s1)
// Output:
// "123"
set s2 to convert.tostring(true)
show(s2)
// Output:
// "true"
set s3 to convert.tostring([1,2,3])
show(s3)
// Output:
// "[1, 2, 3]"
set s4 to convert.tostring({"a":1})
show(s4)
// Output:
// "{a: 1}"
isint(x)
set i1 to convert.isint(10.0)
show(i1)
// Output:
// true
set i2 to convert.isint(10.5)
show(i2)
// Output:
// false
set i3 to convert.isint("5")
show(i3)
// Output:
// false
isalnum(x)
set a1 to convert.isalnum("abc123")
show(a1)
// Output:
// true
set a2 to convert.isalnum("abc 123")
show(a2)
// Output:
// false
isdigit(x)
set d1 to convert.isdigit("2025")
show(d1)
// Output:
// true
set d2 to convert.isdigit("20a5")
show(d2)
// Output:
// false
isdouble(x)
set dd1 to convert.isdouble(3.14)
show(dd1)
// Output:
// true
set dd2 to convert.isdouble(3.0)
show(dd2)
// Output:
// false
isstring(x)
set str1 to convert.isstring("hello")
show(str1)
// Output:
// true
set str2 to convert.isstring(123)
show(str2)
// Output:
// false
islist(x)
set l1 to convert.islist([1,2,3])
show(l1)
// Output:
// true
set l2 to convert.islist("not a list")
show(l2)
// Output:
// false
isdict(x)
set m1 to convert.isdict({"key": "value"})
show(m1)
// Output:
// true
set m2 to convert.isdict([1,2,3])
show(m2)
// Output:
// false
typeof(x)
set t1 to convert.typeof(123)
show(t1)
// Output:
// "number"
set t2 to convert.typeof("text")
show(t2)
// Output:
// "string"
set t3 to convert.typeof(true)
show(t3)
// Output:
// "bool"
set t4 to convert.typeof([1,2])
show(t4)
// Output:
// "list"
set t5 to convert.typeof({"a": 1})
show(t5)
// Output:
// "dict"
set t6 to convert.typeof(convert.toint)
show(t6)
// Output:
// "function"
set t7 to convert.typeof(nil)
show(t7)
// Output:
// "null"
Conclusion
To use conversion and type-checking functions in EasyBite:
- Import the module:
import convert
- Or import specific functions:
from convert import toint, typeof
All functions must be called through the convert
module or via selective import. Direct method calls on values without importing are not supported.