@inaut/math-functions
Version:
Executes code-lines with function calls like Excel
686 lines (659 loc) • 68.4 kB
HTML
<!doctype html>
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>@inaut/math-functions</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.js" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">@inaut/math-functions</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
<input type="checkbox" id="tsd-filter-only-exported" />
<label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<ul class="tsd-breadcrumb">
<li>
<a href="globals.html">Globals</a>
</li>
</ul>
<h1> @inaut/math-functions</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<!-- TOC -->
<ul>
<li><a href="#1-mathematic-functions">1. Mathematic functions</a><ul>
<li><a href="#11-supported-datatypes">1.1. Supported datatypes</a><ul>
<li><a href="#111-boolean">1.1.1. Boolean</a></li>
<li><a href="#112-string">1.1.2. String</a></li>
<li><a href="#113-number">1.1.3. Number</a></li>
<li><a href="#114-array">1.1.4. Array</a></li>
<li><a href="#115-functions">1.1.5. Functions</a></li>
</ul>
</li>
<li><a href="#12-order-of-execution">1.2. Order of execution</a></li>
</ul>
</li>
<li><a href="#2-installation-and-usage">2. Installation and Usage</a><ul>
<li><a href="#21-installation">2.1. Installation</a></li>
<li><a href="#22-usage">2.2. Usage</a></li>
<li><a href="#23-setup-environment">2.3. Setup Environment</a></li>
<li><a href="#24-add-your-own-function">2.4. Add your own function</a><ul>
<li><a href="#241-basicfunction-class">2.4.1. BasicFunction-Class</a></li>
<li><a href="#242-create-your-own-function">2.4.2. Create your own function</a></li>
<li><a href="#243-register-function">2.4.3. Register Function</a></li>
</ul>
</li>
<li><a href="#25-open-issues">2.5. Open issues</a><ul>
<li><a href="#251-asyncron-function-support-minor">2.5.1. Asyncron function support <strong>minor</strong></a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#3-version-history">3. Version history</a><ul>
<li><a href="#31-v130-2022-07-01">3.1. v1.3.0 (2022-07-01)</a></li>
<li><a href="#32-v131-2022-07-06">3.2. v1.3.1 (2022-07-06)</a></li>
</ul>
</li>
</ul>
<!-- /TOC -->
<a href="#1-mathematic-functions" id="1-mathematic-functions" style="color: inherit; text-decoration: none;">
<h1>1. Mathematic functions</h1>
</a>
<p>Executes a string-expression.<br>Script-engine is used to read the expression, build a tree of nodes, validates and calculates the result by executing the nodes.</p>
<p>By default, expression are stored for later reuse. A script-environment, the context of the subject, has to be defined.</p>
<a href="#11-supported-datatypes" id="11-supported-datatypes" style="color: inherit; text-decoration: none;">
<h2>1.1. Supported datatypes</h2>
</a>
<p>Following datatypes are supported:</p>
<ul>
<li>boolean</li>
<li>string</li>
<li>number</li>
<li>arrays</li>
</ul>
<a href="#111-boolean" id="111-boolean" style="color: inherit; text-decoration: none;">
<h3>1.1.1. Boolean</h3>
</a>
<p>Following boolean values are possible:</p>
<ul>
<li>false</li>
<li>true</li>
</ul>
<a href="#112-string" id="112-string" style="color: inherit; text-decoration: none;">
<h3>1.1.2. String</h3>
</a>
<p>A string starts and ends with <code>'</code> (single-quote). A backslash can be used to escape the single-quote (\').
Examples of strings:</p>
<ul>
<li>'Hello World!'</li>
<li>'Hello \'World\'!' => 'Hello 'World'!'</li>
</ul>
<a href="#113-number" id="113-number" style="color: inherit; text-decoration: none;">
<h3>1.1.3. Number</h3>
</a>
<p>Number starts and ends with numbers and dot. Only one dot is allowed. All numbers are interpreted as floating point number in real-format.
If the number starts with 0x or 0b, the values are interpreted in hexa-decimal (e.g. 0xFFFF) or binary (0b1010).
Example of numbers:</p>
<ul>
<li>12.3</li>
<li>.123 => 0.123</li>
<li><ol start="123">
<li>=> 123.0</li>
</ol>
</li>
<li>-12.3</li>
<li>-.123 => -0.123 ==> if there is an operator or backet before the minus, or the minus is the first character in the string</li>
<li>0xAF12 => 44818</li>
<li>0b1001 => 9</li>
</ul>
<a href="#114-array" id="114-array" style="color: inherit; text-decoration: none;">
<h3>1.1.4. Array</h3>
</a>
<p>Array is a list of items. An array starts with [-bracket and ends with ].
Comma <code>,</code>is used as delimiter between the items. Only arrays of one datatype are supported.
An item can be from datatype</p>
<ul>
<li>boolean</li>
<li>string</li>
<li>number</li>
<li>function</li>
</ul>
<a href="#115-functions" id="115-functions" style="color: inherit; text-decoration: none;">
<h3>1.1.5. Functions</h3>
</a>
<p>Functions are returning a value based on the provided argument(s) and their algorithmus. If the provided arguments are invalid, an object instance of <code>ExpressionError</code> will be returned. Function <code>IF_ERROR()</code> can be used to get a substitute value instead the error-value back.</p>
<p>For a list of available function, please check api-documentation directory <code>doc</code> <a href="classes/_math_functions_functions_base_function_.basefunction.html">BaseFunction</a>.</p>
<a href="#12-order-of-execution" id="12-order-of-execution" style="color: inherit; text-decoration: none;">
<h2>1.2. Order of execution</h2>
</a>
<p>Operations are executed according their priority. Operations with higher priority are executed before lower once.
Operations with the same priority are executed from the left to the right. The priority follows the standard of javascript.
Arguments of functions, operations are functions as well, are executed from the left to the right.
The node tree is executed from the leave-nodes, down to the root-node. Higher priority operations are moving deeper into the tree than nodes with low priority.</p>
<a href="#2-installation-and-usage" id="2-installation-and-usage" style="color: inherit; text-decoration: none;">
<h1>2. Installation and Usage</h1>
</a>
<a href="#21-installation" id="21-installation" style="color: inherit; text-decoration: none;">
<h2>2.1. Installation</h2>
</a>
<p>For installation, call</p>
<pre><code>npm <span class="hljs-keyword">install</span> active-<span class="hljs-keyword">content</span> <span class="hljs-comment">--save</span></code></pre>
<a href="#22-usage" id="22-usage" style="color: inherit; text-decoration: none;">
<h2>2.2. Usage</h2>
</a>
<p>Setup ScriptEngine</p>
<pre><code><span class="hljs-keyword">import</span> { ScriptEngine } <span class="hljs-keyword">from</span> <span class="hljs-string">'active-content'</span>;
<span class="hljs-comment">// get singleton of the engine</span>
<span class="hljs-keyword">const</span> engine = ScriptEngine.GET(); <span class="hljs-comment">//or new ScriptEngine(), if only local use is needed;</span>
<span class="hljs-comment">// set environment</span>
engine.setEnvironment({<span class="hljs-attr">requestData</span>: <span class="hljs-function">(<span class="hljs-params">selector, args</span>) =></span> {
<span class="hljs-keyword">switch</span>(selector) {
<span class="hljs-keyword">case</span> <span class="hljs-string">`GET_VALUE`</span>:
}
}})
<span class="hljs-comment">//import here your own functions</span>
<span class="hljs-keyword">import</span>(<span class="hljs-string">"./file-path-to-function"</span>);</code></pre><p>Execute an expression</p>
<pre><code><span class="hljs-comment">// somewhere later</span>
<span class="hljs-comment">// create and execute expression</span>
const expr = <span class="hljs-string">"IF(... , ..., ...)"</span>;
const result = ScriptEngine.<span class="hljs-constructor">GET()</span>.execute<span class="hljs-constructor">Boolean(<span class="hljs-params">expr</span>, <span class="hljs-string">"myObject.propertyName"</span>)</span>; <span class="hljs-comment">// or: engine.executeBoolean(), egine.executeNumber(), engine.executeString(), execute()</span>
...</code></pre>
<a href="#23-setup-environment" id="23-setup-environment" style="color: inherit; text-decoration: none;">
<h2>2.3. Setup Environment</h2>
</a>
<p>You have to setup an environment-object and apply this object to the script-engine via the method <code>setEnvironment()</code> or at each call of any <code>execution</code>-Method.</p>
<p>A function can request data of your environmet (context of the subject you are executiong the expression) through the <code>requestData</code>-Method.
The argument <code>selector</code> defines the data a function requests, <code>args</code> are optional arguments for detailed specification of the data. The method returns the data requested or throws an Error.</p>
<p>An instance of class <a href="classes/_math_functions_default_environment_.defaultenvironment.html">DefaultEnvironment</a> can be set.</p>
<table>
<thead>
<tr>
<th>selector</th>
<th align="center">args</th>
<th align="center">call by function</th>
<th align="center">return</th>
<th align="center">description</th>
</tr>
</thead>
<tbody><tr>
<td>GET_VALUE</td>
<td align="center">group: group the property belongs (data, notify,..);<br> name: Name of the Property</td>
<td align="center">GET_VALUE()</td>
<td align="center">string<br>boolean<br>number</td>
<td align="center">Returns the value of the requested property</td>
</tr>
<tr>
<td>GET_VALUE_STATE</td>
<td align="center">group: group the property belongs (data, notify,..);<br> name: Name of the Property</td>
<td align="center">GET_VALUE_STATE()</td>
<td align="center">boolean</td>
<td align="center">Returns the read-status of the property (true: value is valid)</td>
</tr>
<tr>
<td>GET_VALUE_TS</td>
<td align="center">group: string = group the property belongs (data, notify,..);<br> name: string = Name of the Property</td>
<td align="center">GET_VALUE_TS()</td>
<td align="center">number</td>
<td align="center">Returns the timestamp of the property as unix-timestamp in <code>sec</code></td>
</tr>
<tr>
<td>GET_DATE_TIME</td>
<td align="center">useLocalTime: boolean</td>
<td align="center">GET_DATE_TIME()</td>
<td align="center">Date</td>
<td align="center">Should return the actual date-time. Is omitted (throws an error) the date-time from the system will be taken (call of new Date());</td>
</tr>
<tr>
<td>SET_VALUE</td>
<td align="center">group: string = group the property belongs (data, notify,..);<br> name: string = Name of the Property<br>value: any = value to set</td>
<td align="center">SET_VALUE()</td>
<td align="center">void</td>
<td align="center">Set the value of the variable.</td>
</tr>
</tbody></table>
<a href="#24-add-your-own-function" id="24-add-your-own-function" style="color: inherit; text-decoration: none;">
<h2>2.4. Add your own function</h2>
</a>
<p>Workarround until another solution is found (reason: extend class BaseFunction for lib is not working):</p>
<a href="#241-basicfunction-class" id="241-basicfunction-class" style="color: inherit; text-decoration: none;">
<h3>2.4.1. BasicFunction-Class</h3>
</a>
<p>Create a file named BasicFunctin.ts and insert following content.</p>
<pre><code><span class="hljs-keyword">import</span> { IBaseFunction, ExpressionError } <span class="hljs-keyword">from</span> <span class="hljs-string">'@inaut/math-functions'</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> BaseFunction <span class="hljs-keyword">implements</span> IBaseFunction{
<span class="hljs-keyword">private</span> name: <span class="hljs-built_in">string</span>;
<span class="hljs-comment">/**
* Returns the name of the function
*/</span>
<span class="hljs-keyword">public</span> getName() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.name;
}
<span class="hljs-keyword">public</span> toString() {
<span class="hljs-keyword">return</span> <span class="hljs-string">'CodeFunction '</span> + <span class="hljs-keyword">this</span>.getName();
}
<span class="hljs-keyword">private</span> operation: <span class="hljs-built_in">string</span> | <span class="hljs-literal">undefined</span>;
<span class="hljs-comment">/**
* Returns true if this function is also available as operation (using operator)
*/</span>
<span class="hljs-keyword">public</span> isOperator() {
<span class="hljs-keyword">return</span> !!<span class="hljs-keyword">this</span>.operation;
}
<span class="hljs-keyword">private</span> priority: <span class="hljs-built_in">number</span> | <span class="hljs-literal">undefined</span>;
<span class="hljs-comment">/**
* Returns the priority of this function.
* Only needed for operators.
*/</span>
<span class="hljs-keyword">public</span> getPriority() {
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.priority === <span class="hljs-literal">undefined</span>) {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-keyword">this</span>.toString() + <span class="hljs-string">' is an operation, but priority is not defined!'</span>);
}
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.priority;
}
<span class="hljs-comment">/**
* Returns true if the priority of this function is higher than the provided priority
*/</span>
<span class="hljs-keyword">public</span> hasHigherPriorityThan(priority: <span class="hljs-built_in">number</span>) {
<span class="hljs-keyword">const</span> myPriority = <span class="hljs-keyword">this</span>.getPriority();
<span class="hljs-keyword">return</span> myPriority !== <span class="hljs-literal">undefined</span> ? myPriority > priority : <span class="hljs-literal">false</span>;
}
<span class="hljs-comment">/**
* Returns the operator-character of this function.
* Throws an error if this function is not useable as operation.
*/</span>
<span class="hljs-keyword">public</span> getOperator() {
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.operation) {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.operation;
} <span class="hljs-keyword">else</span> {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Function '</span> + <span class="hljs-keyword">this</span>.getName() + <span class="hljs-string">' has no operator!'</span>);
}
}
<span class="hljs-keyword">private</span> description = <span class="hljs-string">""</span>;
<span class="hljs-comment">/**
* Returns the description of this function.
* An empty string if a description is not available.
*/</span>
<span class="hljs-keyword">public</span> getDescription() {
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.description === <span class="hljs-literal">undefined</span>) {
<span class="hljs-keyword">this</span>.description = <span class="hljs-string">""</span>;
}
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.description;
};
<span class="hljs-keyword">private</span> storing = <span class="hljs-literal">false</span>;
<span class="hljs-comment">/**
* Returns true if this function is storing values between the calls. So, an instance needs to be created for each occurrence.
*/</span>
<span class="hljs-keyword">public</span> isStoring() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.storing;
}
<span class="hljs-keyword">private</span> asyncron = <span class="hljs-literal">false</span>;
<span class="hljs-comment">/**
* Returns true if this function must be called asyncron and returns the value not immediately.
*/</span>
<span class="hljs-keyword">public</span> isAsyncron() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.asyncron;
}
<span class="hljs-comment">/**
* Creates a new operator-function
* @param name Name of the function used in script. Use capital letters\ (e.g. `MY_FUNCTION`)
* @param priority Priority of this operation according javascript-standard. Higher value => higher priority. Operation with higher priority are called first. (https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
* @param operator Character(s) used for this operator function\ (e.g. `>=`, `==`, `!=`).
* @param description Description about the function
* @param storesValues If true, function contains data to be hold until next call. Default is false.
*/</span>
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">constructor</span>(<span class="hljs-params">name: <span class="hljs-built_in">string</span>, priority: <span class="hljs-built_in">number</span>, operator: <span class="hljs-built_in">string</span>, description?: <span class="hljs-built_in">string</span>, storesValues?: <span class="hljs-built_in">boolean</span></span>);
<span class="hljs-comment">/**
* Creates a new function
* @param name Name of the function used in script. Use capital letters\ (e.g. `MY_FUNCTION`)
* @param description Description about the function
* @param storesValues If true, function contains data to be hold until next call. Default is false.
* @param isAsyncron If true, function must be executed asyncron. Default is false. Therefore override method <a href="classes/_math_functions_functions_base_function_.basefunction.html#executeasync">BaseFunction.executeAsync</a>. If false, override <a href="classes/_math_functions_functions_base_function_.basefunction.html#execute">BaseFunction.execute</a>
*/</span>
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">constructor</span>(<span class="hljs-params">name: <span class="hljs-built_in">string</span>, description?: <span class="hljs-built_in">string</span>, storesValues?: <span class="hljs-built_in">boolean</span>, isAsyncron?: <span class="hljs-built_in">boolean</span> </span>);
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">constructor</span>(<span class="hljs-params">name: <span class="hljs-built_in">string</span>, priorityOrDescription?: <span class="hljs-built_in">number</span> | <span class="hljs-built_in">string</span>, operationOrDescriptionOrStores?: <span class="hljs-built_in">string</span> | <span class="hljs-built_in">boolean</span>, descriptionOrAsync?: <span class="hljs-built_in">string</span> | <span class="hljs-built_in">boolean</span>, stores?: <span class="hljs-built_in">boolean</span></span>) {
<span class="hljs-keyword">if</span> (!name) {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Argument `name` is missing!'</span>);
}
<span class="hljs-keyword">this</span>.name = name;
<span class="hljs-keyword">if</span> (priorityOrDescription !== <span class="hljs-literal">undefined</span> && <span class="hljs-keyword">typeof</span> priorityOrDescription === <span class="hljs-string">'number'</span>) {
<span class="hljs-comment">// first method signature</span>
<span class="hljs-keyword">this</span>.priority = priorityOrDescription;
<span class="hljs-comment">// operator</span>
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> operationOrDescriptionOrStores === <span class="hljs-string">'string'</span>) {
<span class="hljs-keyword">this</span>.operation = operationOrDescriptionOrStores;
} <span class="hljs-keyword">else</span> {
<span class="hljs-keyword">if</span> (operationOrDescriptionOrStores === <span class="hljs-literal">undefined</span>) {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Argument `operation` is missing!'</span>);
} <span class="hljs-keyword">else</span> {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Argument `operation` is not from type `string`!'</span>);
}
}
<span class="hljs-comment">// description</span>
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> descriptionOrAsync === <span class="hljs-string">'string'</span>) {
<span class="hljs-keyword">this</span>.description = descriptionOrAsync;
}
<span class="hljs-keyword">if</span> (stores !== <span class="hljs-literal">undefined</span>) {
<span class="hljs-keyword">this</span>.storing = stores;
}
} <span class="hljs-keyword">else</span> {
<span class="hljs-comment">// second method signature</span>
<span class="hljs-comment">// description</span>
<span class="hljs-keyword">if</span> (priorityOrDescription && <span class="hljs-keyword">typeof</span> priorityOrDescription === <span class="hljs-string">'string'</span>) {
<span class="hljs-keyword">this</span>.description = priorityOrDescription;
}
<span class="hljs-keyword">if</span> (operationOrDescriptionOrStores !== <span class="hljs-literal">undefined</span> && <span class="hljs-keyword">typeof</span> operationOrDescriptionOrStores === <span class="hljs-string">'boolean'</span>) {
<span class="hljs-keyword">this</span>.storing = operationOrDescriptionOrStores;
}
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> descriptionOrAsync === <span class="hljs-string">'boolean'</span>) {
<span class="hljs-keyword">this</span>.asyncron = descriptionOrAsync;
}
}
}
<span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> execute(preexecutedArguments: <span class="hljs-built_in">any</span>[], environment: <span class="hljs-built_in">any</span>, node: Node, execPath?: <span class="hljs-built_in">string</span>): <span class="hljs-built_in">any</span>;
<span class="hljs-keyword">public</span> executeAsync(preexecutedArguments: <span class="hljs-built_in">any</span>[], environment: <span class="hljs-built_in">any</span>, node: Node, execPath?: <span class="hljs-built_in">string</span>): <span class="hljs-built_in">Promise</span><<span class="hljs-built_in">any</span>> {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span><<span class="hljs-built_in">any</span>><span class="hljs-function">(<span class="hljs-params">(<span class="hljs-params">resolve, reject</span>) => {
resolve(<span class="hljs-params"><span class="hljs-keyword">this</span>.execute(<span class="hljs-params">preexecutedArguments, environment, node</span>)</span>);
}</span>);
}
/**
* <span class="hljs-params">Returns</span> <span class="hljs-params">true</span>, <span class="hljs-params">if</span> <span class="hljs-params">the</span> <span class="hljs-params">argument</span> (<span class="hljs-params">node-children</span>) <span class="hljs-params">should</span> <span class="hljs-params">be</span> <span class="hljs-params">executed</span> <span class="hljs-params">before</span> `<span class="hljs-params">execute</span>` <span class="hljs-params">of</span> <span class="hljs-params">this</span> <span class="hljs-params">function</span> <span class="hljs-params">is</span> <span class="hljs-params">called</span>.
* <span class="hljs-params">By</span> <span class="hljs-params">default</span>, <span class="hljs-params">returns</span> <span class="hljs-params">true</span> <span class="hljs-params">for</span> <span class="hljs-params">all</span> <span class="hljs-params">arguments</span>. <span class="hljs-params">Override</span> <span class="hljs-params">in</span> <span class="hljs-params">function</span> <span class="hljs-params">if</span> <span class="hljs-params">certain</span> <span class="hljs-params">arguments</span> <span class="hljs-params">are</span> <span class="hljs-params">executed</span> <span class="hljs-params">for</span> <span class="hljs-params">getting</span> <span class="hljs-params">ther</span> <span class="hljs-params">value</span> <span class="hljs-params">inside</span> <span class="hljs-params">the</span> `<span class="hljs-params">execute</span>`-<span class="hljs-params">method</span>.
* @<span class="hljs-params">param</span> <span class="hljs-params">index</span> <span class="hljs-params">Zero</span>-<span class="hljs-params">based</span> <span class="hljs-params">index</span> <span class="hljs-params">of</span> <span class="hljs-params">the</span> <span class="hljs-params">argument</span>
* @<span class="hljs-params">param</span> <span class="hljs-params">node</span> <span class="hljs-params">The</span> <span class="hljs-params">node</span>, <span class="hljs-params">none</span> <span class="hljs-params">executed</span> (<span class="hljs-params">result is not availabe at that time</span>)
*/
<span class="hljs-params">public</span> <span class="hljs-params">isPreexecutedArgument</span>(<span class="hljs-params">index: <span class="hljs-built_in">number</span>, node: Node</span>): <span class="hljs-params">boolean</span> {
<span class="hljs-params">return</span> <span class="hljs-params">true</span>;
}
/**
* <span class="hljs-params">Returns</span> <span class="hljs-params">true</span> <span class="hljs-params">if</span> <span class="hljs-params">args</span> <span class="hljs-params">is</span> <span class="hljs-params">an</span> <span class="hljs-params">ExpressionError</span>-<span class="hljs-params">object</span> <span class="hljs-params">or</span> <span class="hljs-params">an</span> <span class="hljs-params">array</span> <span class="hljs-params">which</span> <span class="hljs-params">contains</span> <span class="hljs-params">an</span> <span class="hljs-params">ExpressionError</span>-<span class="hljs-params">object</span>.
*/
<span class="hljs-params">protected</span> <span class="hljs-params">hasArgumentError</span>(<span class="hljs-params">args: <span class="hljs-built_in">any</span> | <span class="hljs-built_in">any</span>[]</span>) {
<span class="hljs-params">if</span> (<span class="hljs-params">args && <span class="hljs-built_in">Array</span>.isArray(<span class="hljs-params">args</span>)</span>) {
<span class="hljs-params">return</span> <span class="hljs-params">args</span>.<span class="hljs-params">some</span>(<span class="hljs-params">arg => <span class="hljs-keyword">this</span>.isExpressionError(<span class="hljs-params">arg</span>)</span>);
} <span class="hljs-params">else</span> <span class="hljs-params">if</span> (<span class="hljs-params">args && <span class="hljs-keyword">typeof</span> args === 'object'</span>) {
<span class="hljs-params">return</span> <span class="hljs-params">this</span>.<span class="hljs-params">isExpressionError</span>(<span class="hljs-params">args</span>);
} <span class="hljs-params">else</span> {
<span class="hljs-params">return</span> <span class="hljs-params">false</span>;
}
}
/**
* <span class="hljs-params">Returns</span> <span class="hljs-params">the</span> <span class="hljs-params">first</span> <span class="hljs-params">argument</span> <span class="hljs-params">with</span> <span class="hljs-params">error</span> <span class="hljs-params">inside</span> <span class="hljs-params">args</span>, <span class="hljs-params">if</span> <span class="hljs-params">args</span> <span class="hljs-params">is</span> <span class="hljs-params">an</span> <span class="hljs-params">array</span>. <span class="hljs-params">Or</span> <span class="hljs-params">args</span> <span class="hljs-params">itself</span>, <span class="hljs-params">if</span> <span class="hljs-params">args</span> <span class="hljs-params">is</span> <span class="hljs-params">an</span> <span class="hljs-params">object</span> <span class="hljs-params">of</span> <span class="hljs-params">ExpressionError</span> (<span class="hljs-params">or derived</span>).
*/
<span class="hljs-params">protected</span> <span class="hljs-params">getArgumentError</span>(<span class="hljs-params">args: <span class="hljs-built_in">any</span> | <span class="hljs-built_in">any</span>[] </span>): <span class="hljs-params">ExpressionError</span> | <span class="hljs-params">undefined</span> {
<span class="hljs-params">if</span> (<span class="hljs-params">args && <span class="hljs-built_in">Array</span>.isArray(<span class="hljs-params">args</span>)</span>) {
<span class="hljs-params">return</span> <span class="hljs-params">args</span>.<span class="hljs-params">find</span>(<span class="hljs-params">arg => <span class="hljs-keyword">this</span>.isExpressionError(<span class="hljs-params">arg</span>)</span>);
} <span class="hljs-params">else</span> <span class="hljs-params">if</span> (<span class="hljs-params">args && <span class="hljs-keyword">typeof</span> args === 'object'</span>) {
<span class="hljs-params">return</span> <span class="hljs-params">this</span>.<span class="hljs-params">isExpressionError</span>(<span class="hljs-params">args</span>) ? <span class="hljs-params">args</span> : <span class="hljs-params">undefined</span>;
} <span class="hljs-params">else</span> {
<span class="hljs-params">return</span> <span class="hljs-params">undefined</span>;
}
}
<span class="hljs-params">protected</span> <span class="hljs-params">isExpressionError</span>(<span class="hljs-params">objectToCheck: <span class="hljs-built_in">any</span></span>) {
<span class="hljs-params">if</span> (<span class="hljs-params">objectToCheck && <span class="hljs-keyword">typeof</span> objectToCheck === 'object'</span>) {
<span class="hljs-params">const</span> <span class="hljs-params">errObject</span> = <span class="hljs-params">objectToCheck</span> <span class="hljs-params">as</span> <span class="hljs-params">ExpressionError</span>;
<span class="hljs-params">return</span> <span class="hljs-params">errObject</span>.<span class="hljs-params">getPosition</span> && <span class="hljs-params">errObject</span>.<span class="hljs-params">getPosition</span><span class="hljs-params">()</span> !== <span class="hljs-params">undefined</span> && <span class="hljs-params">errObject</span>.<span class="hljs-params">message</span> !== <span class="hljs-params">undefined</span>;
} <span class="hljs-params">else</span> {
<span class="hljs-params">return</span> <span class="hljs-params">false</span>;
}
}
<span class="hljs-params">public</span> <span class="hljs-params">abstract</span> <span class="hljs-params">clone</span><span class="hljs-params">()</span>: <span class="hljs-params">BaseFunction</span>;
}</span></code></pre>
<a href="#242-create-your-own-function" id="242-create-your-own-function" style="color: inherit; text-decoration: none;">
<h3>2.4.2. Create your own function</h3>
</a>
<p>Create a typescript-file.</p>
<pre><code><span class="hljs-keyword">import</span> { ScriptEnvironment, Node, ArgumentWrongTypeError, FunctionError, ArgumentMissingError } <span class="hljs-keyword">from</span> <span class="hljs-string">'@inaut/math-functions'</span>;
<span class="hljs-keyword">import</span> { BaseFunction } <span class="hljs-keyword">from</span> <span class="hljs-string">'./base-function'</span>;
<span class="hljs-comment">/**
* Convert degree to radiant
*
* ```
* TO_RAD(degree:number) => number;
* ```
*
**/</span>
<span class="hljs-comment">// tslint:disable-next-line:class-name</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Function_TO_RAD <span class="hljs-keyword">extends</span> BaseFunction {
<span class="hljs-meta">@CodeFunction</span>()
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> META() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Function_TO_RAD();
}
<span class="hljs-keyword">private</span> <span class="hljs-keyword">constructor</span>(<span class="hljs-params"></span>) {
<span class="hljs-keyword">super</span>(<span class="hljs-string">'TO_RAD'</span>, <span class="hljs-string">'Convert degree to radiant'</span>);
}
<span class="hljs-keyword">public</span> execute(preexcArguments: <span class="hljs-built_in">any</span>[], environment: ScriptEnvironment, node: Node, execPath: <span class="hljs-built_in">string</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.hasArgumentError(preexcArguments)) {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.getArgumentError(preexcArguments);
}
<span class="hljs-keyword">try</span> {
<span class="hljs-keyword">if</span> (!<span class="hljs-built_in">Array</span>.isArray(preexcArguments) || preexcArguments.length === <span class="hljs-number">0</span>) {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ArgumentMissingError(node, <span class="hljs-keyword">this</span>, <span class="hljs-string">'degree'</span>, <span class="hljs-number">0</span>);
}
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> preexcArguments[<span class="hljs-number">0</span>] !== <span class="hljs-string">'number'</span>) {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ArgumentWrongTypeError(node, <span class="hljs-keyword">this</span>, <span class="hljs-string">'degree'</span>, <span class="hljs-number">0</span>, <span class="hljs-string">'number'</span>, <span class="hljs-keyword">typeof</span> preexcArguments[<span class="hljs-number">0</span>]);
}
<span class="hljs-keyword">const</span> deg = preexcArguments[<span class="hljs-number">0</span>];
<span class="hljs-keyword">return</span> deg * <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">180.0</span>;
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-keyword">return</span> err;
}
}
<span class="hljs-keyword">public</span> clone() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Function_TO_RAD();
}
}</code></pre>
<a href="#243-register-function" id="243-register-function" style="color: inherit; text-decoration: none;">
<h3>2.4.3. Register Function</h3>
</a>
<p>Register function at your script-engine with call of <code>setFunction()</code>-method.</p>
<p>Example:</p>
<pre><code><span class="hljs-built_in">import</span> { ScriptEngine } from <span class="hljs-string">"@inaut/math-functions"</span>;
<span class="hljs-built_in">import</span> { Function_TO_RAD } from './<span class="hljs-function"><span class="hljs-keyword">function</span>-<span class="hljs-title">to</span>-<span class="hljs-title">rad</span>';
<span class="hljs-title">ScriptEngine</span>.<span class="hljs-title">GET</span><span class="hljs-params">()</span>.<span class="hljs-title">setFunction</span><span class="hljs-params">(Function_TO_RAD.META<span class="hljs-params">()</span>)</span>;</span></code></pre>
<a href="#25-open-issues" id="25-open-issues" style="color: inherit; text-decoration: none;">
<h2>2.5. Open issues</h2>
</a>
<a href="#251-asyncron-function-support-strongminorstrong" id="251-asyncron-function-support-strongminorstrong" style="color: inherit; text-decoration: none;">
<h3>2.5.1. Asyncron function support <strong>minor</strong></h3>
</a>
<p>Support of asyncron call of function and nodes on the path to a asyncron function.</p>
<a href="#3-version-history" id="3-version-history" style="color: inherit; text-decoration: none;">
<h1>3. Version history</h1>
</a>
<a href="#31-v130-2022-07-01" id="31-v130-2022-07-01" style="color: inherit; text-decoration: none;">
<h2>3.1. v1.3.0 (2022-07-01)</h2>
</a>
<ul>
<li><p>Added string functions</p>
<ul>
<li>SPLIT <a href="classes/_math_functions_functions_function_split_.function_split.html">Function_SPLIT</a></li>
<li>REPLACE <a href="classes/_math_functions_functions_function_search_replace_.function_replace.html">Function_REPLACE</a></li>
<li>TRIM <a href="classes/_math_functions_functions_function_trim_.function_trim.html">Function_TRIM</a></li>
<li>TRIM_START <a href="classes/_math_functions_functions_function_trim_start_.function_trim_start.html">Function_TRIM_START</a></li>
<li>TRIM_END <a href="classes/_math_functions_functions_function_trim_end_.function_trim_end.html">Function_TRIM_END</a></li>
<li>CONCATE <a href="classes/_math_functions_functions_function_concate_.function_concate.html">Function_CONCATE</a></li>
<li>JOIN <a href="classes/_math_functions_functions_function_join_.function_join.html">Function_JOIN</a></li>
<li>GET_CHAR <a href="classes/_math_functions_functions_function_get_char_.function_get_char.html">Function_GET_CHAR</a></li>
<li>GET_STRING <a href="classes/_math_functions_functions_function_get_string_.function_get_string.html">Function_GET_STRING</a></li>
<li>IN_STRING <a href="classes/_math_functions_functions_function_in_string_.function_in_string.html">Function_IN_STRING</a></li>
<li>POS_IN_STRING <a href="classes/_math_functions_functions_function_pos_in_string_.function_pos_in_string.html">Function_POS_IN_STRING</a></li>
<li>LEN <a href="classes/_math_functions_functions_function_in_string_.function_in_string.html">Function_IN_STRING</a>: Returns string or array-length</li>
</ul>
</li>
<li><p>Fix searching for function.
Make sure the correct function is taken and not a function starting with the same string.</p>
</li>
</ul>
<a href="#32-v131-2022-07-06" id="32-v131-2022-07-06" style="color: inherit; text-decoration: none;">
<h2>3.2. v1.3.1 (2022-07-06)</h2>
</a>
<ul>
<li>Added functions<ul>
<li>GET_ARRAY_SPLICE <a href="classes/_math_functions_functions_function_get_array_splice_.function_get_array_splice.html">Function_GET_ARRAY_SPLICE</a></li>
<li>TO_LOWER_CASE <a href="classes/_math_functions_functions_function_to_lower_case_.function_to_lower_case.html">Function_TO_LOWER_CASE</a></li>
<li>TO_UPPER_CASE <a href="classes/_math_functions_functions_function_to_upper_case_.function_to_upper_case.html">Function_TO_UPPER_CASE</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class="globals ">
<a href="globals.html"><em>Globals</em></a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_decorator_code_function_decorator_.html">"math-<wbr>functions/decorator/code-<wbr>function.decorator"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_default_environment_.html">"math-<wbr>functions/default-<wbr>environment"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_errors_expression_error_.html">"math-<wbr>functions/errors/expression-<wbr>error"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_errors_function_argument_error_.html">"math-<wbr>functions/errors/function-<wbr>argument-<wbr>error"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_errors_function_argument_missing_error_.html">"math-<wbr>functions/errors/function-<wbr>argument-<wbr>missing-<wbr>error"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_errors_function_argument_wrong_type_error_.html">"math-<wbr>functions/errors/function-<wbr>argument-<wbr>wrong-<wbr>type-<wbr>error"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_errors_function_error_.html">"math-<wbr>functions/errors/function-<wbr>error"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_errors_is_expression_error_.html">"math-<wbr>functions/errors/is-<wbr>expression-<wbr>error"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_errors_node_error_.html">"math-<wbr>functions/errors/node-<wbr>error"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_base_function_.html">"math-<wbr>functions/functions/base-<wbr>function"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_base_function_interface_.html">"math-<wbr>functions/functions/base-<wbr>function-<wbr>interface"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_acos_.html">"math-<wbr>functions/functions/function-<wbr>acos"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_and_.html">"math-<wbr>functions/functions/function-<wbr>and"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_asin_.html">"math-<wbr>functions/functions/function-<wbr>asin"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_atan_.html">"math-<wbr>functions/functions/function-<wbr>atan"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_band_.html">"math-<wbr>functions/functions/function-<wbr>band"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_binary_operation_.html">"math-<wbr>functions/functions/function-<wbr>binary-<wbr>operation"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_bnot_.html">"math-<wbr>functions/functions/function-<wbr>bnot"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_bor_.html">"math-<wbr>functions/functions/function-<wbr>bor"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_bxor_.html">"math-<wbr>functions/functions/function-<wbr>bxor"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_compare_operation_.html">"math-<wbr>functions/functions/function-<wbr>compare-<wbr>operation"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_concate_.html">"math-<wbr>functions/functions/function-<wbr>concate"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_cos_.html">"math-<wbr>functions/functions/function-<wbr>cos"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_diff_.html">"math-<wbr>functions/functions/function-<wbr>diff"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_div_.html">"math-<wbr>functions/functions/function-<wbr>div"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_equal_.html">"math-<wbr>functions/functions/function-<wbr>equal"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_array_element_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>array-<wbr>element"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_array_splice_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>array-<wbr>splice"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_char_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>char"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_date_time_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>date-<wbr>time"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_day_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>day"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_dow_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>dow"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_hour_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>hour"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_minute_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>minute"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_month_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>month"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_second_.html">"math-<wbr>functions/functions/function-<wbr>get-<wbr>second"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_math_functions_functions_function_get_string_.html">"math-<wbr>functions/functions/function-<wbr>get-<wb