The following methods are common to all CSML primitive types.
.type_of()
Return the type of the target value (string, array, object, float, boolean, int, null)
1
any_value.type_of()=> String
Copied!
.to_string()
Return the target value formatted as a string.
1
any_value.to_string()=> String
Copied!
.is_number()
Check if a variable can be interpreted as a number (float or int)
1
string.is_number()=> boolean
2
3
// example
4
do var_int ="42"
5
say var_int.is_number()// true
6
7
do var_float ="42.42"
8
say var_int.is_number()// true
9
10
do obj ={"toto":"tutu"}
11
say obj.is_number()// false
Copied!
.is_int()
Check if the variable can be interpreted as an int
1
string.is_int()=> boolean
2
3
// example
4
do var_int ="42"
5
say var_int.is_number()// true
6
7
do var_float =42.42
8
say var_int.is_number()// false
Copied!
.is_float()
Check if the variable can be interpreted as an float
1
string.is_float()=> boolean
2
3
// example
4
do var_int =42
5
say var_int.is_number()// false
6
7
do var_float =42.42
8
say var_int.is_number()// true
Copied!
.is_error(), .get_info()
Some functions may resolve to an error due to a faulty user input, an unreachable API, or some other bug in the code. You can check the result of such functions call (like HTTP() or App()) with .is_error(), and get more information with .get_info().
1
do x =HTTP("https://somewhere.com/does-not-exist").send()
2
3
if(x.is_error()){
4
// get info a description of the error
5
debug "{{x.get_info()}}"
6
7
// try something else or ask again the user for input!