Utilities

Convert/Cast

Convert to string (string)

Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to return a printable string. If no argument is given, returns the empty string, ''.

 

{ }
[{"data":{"type":"variable","step":"x = 10","var":"x","val":10,"maxpaths":1,"uuid":"d7db099a1a3f9e2df693cd4422bb26cb","x":300,"y":320,"width":120,"height":32},"paths":["9148d39266042bc89aff74e46b1a483b"]},{"data":{"type":"library","step":"convert to string","call":"utilities.cast.string","args":{"var":"{\"~\":\"x\"}"},"maxpaths":1,"uuid":"9148d39266042bc89aff74e46b1a483b","x":300,"y":400,"width":120,"height":32,"utilities":"utilities","utilities.cast.string":"string","data_to_var":"result"},"paths":[]}]

Example Response

{"result":"10"}

Convert to integer (int)

Return an integer object constructed from a number or string x, or return 0 if no arguments are given. If x is a number, it can be a plain integer, a long integer, or a floating point number. If x is floating point, the conversion truncates towards zero. If the argument is outside the integer range, the function returns a long object instead.

 

{ }
[{"data":{"type":"variable","step":"x = '10'","var":"x","val":"10","maxpaths":1,"uuid":"d7db099a1a3f9e2df693cd4422bb26cb","x":300,"y":320,"width":120,"height":32},"paths":["9148d39266042bc89aff74e46b1a483b"]},{"data":{"type":"library","step":"convert to integer","call":"utilities.cast.int","args":{"var":"{\"~\":\"x\"}"},"maxpaths":1,"uuid":"9148d39266042bc89aff74e46b1a483b","x":300,"y":400,"width":120,"height":32,"utilities":"utilities","utilities.cast.int":"int","data_to_var":"result"},"paths":[]}]

Example Response

{"result":10}

Convert to floating point number (number)

Return a floating point number constructed from a number or string x.

If the argument is a string, it must contain a possibly signed decimal or floating point number, possibly embedded in whitespace. The argument may also be [+|-]nan or [+|-]inf. Otherwise, the argument may be a plain or long integer or a floating point number, and a floating point number with the same value is returned. If no argument is given, returns 0.0.

 

{ }
[{"data":{"type":"variable","step":"x = '10.42'","var":"x","val":"10.42","maxpaths":1,"uuid":"d7db099a1a3f9e2df693cd4422bb26cb","x":300,"y":320,"width":120,"height":32},"paths":["9148d39266042bc89aff74e46b1a483b"]},{"data":{"type":"library","step":"convert to number","call":"utilities.cast.number","args":{"var":"{\"~\":\"x\"}"},"maxpaths":1,"uuid":"9148d39266042bc89aff74e46b1a483b","x":300,"y":400,"width":120,"height":32,"utilities":"utilities","utilities.cast.number":"number","data_to_var":"result"},"paths":[]}]

Example Response

{"result":10.42}

Convert to JSON (json)

Converts and returns an object or array as a JSON string

 

{ }
[{"data":{"type":"variable","step":"dict\/object","var":"obj","val":{"list\/array":[1,"2",false],"string":"helloworld","int":10,"bool":true,"number":10.42},"maxpaths":1,"uuid":"d7db099a1a3f9e2df693cd4422bb26cb","x":300,"y":320,"width":120,"height":32},"paths":["9148d39266042bc89aff74e46b1a483b"]},{"data":{"type":"library","step":"convert to JSON string","call":"utilities.cast.json","args":{"var":"{\"~\":\"obj\"}"},"maxpaths":1,"uuid":"9148d39266042bc89aff74e46b1a483b","x":300,"y":400,"width":120,"height":32,"utilities":"utilities","utilities.cast.json":"json","data_to_var":"result"},"paths":[]}]

Example Response

{"result":"{\"list\/array\": [1, \"2\", false], \"int\": 10, \"bool\": true, \"string\": \"helloworld\", \"number\": 10.42}"}

Convert to boolean (bool)

Return a Boolean value, i.e. one of True or False. x is converted using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True. bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.

 

{ }
[{"data":{"type":"variable","step":"x = 'true'","var":"x","val":"true","maxpaths":1,"uuid":"d7db099a1a3f9e2df693cd4422bb26cb","x":300,"y":320,"width":120,"height":32},"paths":["9148d39266042bc89aff74e46b1a483b"]},{"data":{"type":"library","step":"convert to boolean","call":"utilities.cast.bool","args":{"var":"{\"~\":\"x\"}"},"maxpaths":1,"uuid":"9148d39266042bc89aff74e46b1a483b","x":300,"y":400,"width":120,"height":32,"utilities":"utilities","utilities.cast.bool":"bool","data_to_var":"result"},"paths":[]}]

Example Response

{"result":true}

Convert to character (chr)

Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; an error will be raised if i is outside that range.

 

{ }
[{"data":{"type":"variable","step":"x = 97","var":"x","val":97,"maxpaths":1,"uuid":"d7db099a1a3f9e2df693cd4422bb26cb","x":300,"y":320,"width":120,"height":32},"paths":["9148d39266042bc89aff74e46b1a483b"]},{"data":{"type":"library","step":"convert to character","call":"utilities.cast.chr","args":{"var":"{\"~\":\"x\"}"},"maxpaths":1,"uuid":"9148d39266042bc89aff74e46b1a483b","x":300,"y":400,"width":120,"height":32,"utilities":"utilities","utilities.cast.chr":"chr","data_to_var":"result"},"paths":[]}]

Example Response

{"result":"a"}

Convert to hexadecimal (hex)

Convert an integer number (of any size) to a lowercase hexadecimal string prefixed with "0x".

 

{ }
[{"data":{"type":"variable","step":"x = 255","var":"x","val":255,"maxpaths":1,"uuid":"d7db099a1a3f9e2df693cd4422bb26cb","x":300,"y":320,"width":120,"height":32},"paths":["9148d39266042bc89aff74e46b1a483b"]},{"data":{"type":"library","step":"convert to hex","call":"utilities.cast.hex","args":{"var":"{\"~\":\"x\"}"},"maxpaths":1,"uuid":"9148d39266042bc89aff74e46b1a483b","x":300,"y":400,"width":120,"height":32,"utilities":"utilities","utilities.cast.hex":"hex","data_to_var":"result"},"paths":[]}]

Example Response

{"result":"0xff"}

Convert to hash (hash)

Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0).

 

{ }
[{"data":{"type":"variable","step":"x = '10.42'","var":"x","val":"10.42","maxpaths":1,"uuid":"d7db099a1a3f9e2df693cd4422bb26cb","x":300,"y":320,"width":120,"height":32},"paths":["9148d39266042bc89aff74e46b1a483b"]},{"data":{"type":"library","step":"convert string to hash","call":"utilities.cast.hash","args":{"var":"{\"~\":\"x\"}"},"maxpaths":1,"uuid":"9148d39266042bc89aff74e46b1a483b","x":300,"y":400,"width":120,"height":32,"utilities":"utilities","utilities.cast.hash":"hash","data_to_var":"result"},"paths":[]}]

Example Response

{"result":4461898972734738580}