The code of modules and expressions is written in JavaScript and supports the ECMAScript 5 specification. The following built-in objects are available for programming (you can learn more about them here). If you have any suggestions for extending our API, please email us at support@monokot.io.
Object |
Description |
Array |
Represents an untyped array |
Boolean |
Represents a boolean value |
DataView |
Intended for converting numbers to bytes and vice versa |
Date |
Represents date and time |
Error |
Represents an exception |
JSON |
Intended for creating objects from JSON string |
Map |
Represents an object containing key/value pairs |
Math |
Intended for accessing mathematical operations |
Number |
Represents a number |
RegExp |
Intended for working with regular expressions |
Set |
Represents a set of objects with key access |
String |
Represents a string |
TypedArray |
Represents a typed array, e.g. Int16Array |
For each expression, a global object context is defined, which can be used to access context-dependent properties and methods, i.e., during the execution of an expression, the context object is filled with the data of the expression currently being executed. For example, the following code is given for all expressions:
if (context.expression.id == 'MyExpression')
return 111;
else if (context.expression.id == 'NotMineExpression')
return 999;
else return 0;
In this case, MyExpression will return 111, NotMineExpression will return 999, and all others will return 0. The above mentioned script can be declared in modules as a function, which will be an example of code reuse. Then, the expression will return a function as a result.
Module1 code:
function getResult() {
if (context.expression.id == 'MyExpression')
return 111;
else if (context.expression.id == 'NotMineExpression')
return 999;
else return 0;
}
Expressions code:
return getResult();