Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • ScriptEngine

Index

Constructors

constructor

  • Parameters

    Returns ScriptEngine

Properties

Private environment

environment: ScriptEnvironment | undefined

Private errorLogs

errorLogs: Map<string, boolean> = new Map<string, boolean>()

Private storedExpressions

storedExpressions: Map<string, BracketNode> = new Map<string, BracketNode>()

Static ARGUMENT_DELIMITER

ARGUMENT_DELIMITER: "," = ","

Static ARRAY_CLOSE

ARRAY_CLOSE: "]" = "]"

Static ARRAY_OPEN

ARRAY_OPEN: "[" = "["

Static BRACKET_CLOSE

BRACKET_CLOSE: ")" = ")"

Static BRACKET_OPEN

BRACKET_OPEN: "(" = "("

Static ESCAPE_CHAR

ESCAPE_CHAR: "\" = "\"

Static EXPRESSION_INDICATOR_END

EXPRESSION_INDICATOR_END: "]" = "]"

Static EXPRESSION_INDICATOR_START

EXPRESSION_INDICATOR_START: "=[" = "=["

Static STRING_CHAR

STRING_CHAR: "'" = "'"

Static Private inst

Methods

Private checkArray

  • Is looking for an array at the expression starting at zero-based actual.index-position. An array starts with [ and ends with ]; , is used as delimiter between array-items.

    Items can be from type

    • boolean (true/false)
    • number (e.g.: 42432.2)
    • string (e.g.: 'Hello World!')

    Type mismatch is not supported. Empty arrays are allowed.
    If the next field is an array, adds a array-node as children to the actual node. Items are added as children to the array-node. Is not changing the actual node (step in or out). Returns true, if an array was found at the start-position.

    Parameters

    Returns void

Private checkBoolean

  • Is looking for a boolean (true/false) at the expression starting at zero-based actual.index-position.

    If the next field is a boolean, adds a boolean-node as children to the actual node. Is not changing the actual node (step in or out). Returns true, if a boolean constant was found at the start-position.

    Parameters

    Returns boolean

Private checkCloseBracket

  • Is looking for a close-bracket at the expression starting at zero-based actual.index-position.

    If the next field is a close-bracket, sets the parent node as actual node (step-out). Returns true, if a close-bracket was found at the start-position.

    Parameters

    Returns boolean

Private checkFunction

  • Is looking for a function at the expression starting at zero-based actual.index-position. A function starts with a name, followed by a open-bracket (, a list of arguments and ends with a close-bracket ).

    If the next field is a function, adds a function-node as children to the actual node. Is not changing the actual node (step in or out). Returns true, if a function was found at the start-position.

    Parameters

    Returns boolean

Private checkNumber

  • Is looking for a number at the expression starting at zero-based actual.index-position. A number can start with a letter between 0-9 or dot and ends with a number. A number cannot have spaces either other signes like commas and only one dot.
    Valid numbers are:

    • 12
    • 12.3
    • .123
    • 123.

    Converts the number to a floating-point. If the next field is a number, adds a number-node as children to the actual node. Is not changing the actual node (step in or out). Returns true, if a number was found at the start-position.

    Parameters

    Returns boolean

Private checkOpenBracket

  • Is looking for an open-bracket at the expression starting at zero-based actual.index-position.

    If the next field is a bracket, adds a bracket-node as children to the actual node and sets this new bracket-node as actual-node. Returns true, if a open-bracket was found at the start-position.

    Parameters

    Returns boolean

Private checkOperator

  • Is looking for an operator (e.g.: +, -, /, *, >=, <=, &&, ...) at the expression starting at zero-based actual.index-position.

    If the next field is an operator, adds an operator-node as children to the actual node. Is not changing the actual node (step in or out). Returns true, if an operator was found at the start-position.

    Parameters

    Returns boolean

Private checkString

  • Is looking for a string at the expression starting at zero-based actual.index-position. A string starts with ' and ends with '. Use escape for using single-quote in string (\').

    Reads the characters between the start- and end-quote. If the next field is a string, adds a string-node as children to the actual node. Is not changing the actual node (step in or out). Returns true, if a string was found at the start-position.

    Parameters

    Returns boolean

clearStorage

  • clearStorage(): void
  • Removes all stored expression from the storage

    Returns void

Private countErrors

  • countErrors(): number
  • Returns number

Private createFlatNodeTree

  • createFlatNodeTree(expression: string, rootNode: Node, startIndex?: undefined | number, location?: "root" | "function-argument" | "array-argument"): ICheckArguments
  • Parameters

    • expression: string
    • rootNode: Node
    • Optional startIndex: undefined | number
    • Default value location: "root" | "function-argument" | "array-argument" = "root"

    Returns ICheckArguments

Private createRootNodeTree

  • Parameters

    • expression: string

    Returns BracketNode

deleteFromStorage

  • deleteFromStorage(execPath: string): void
  • Removes the expression of the provided execution-path from the storage.

    Parameters

    • execPath: string

    Returns void

execute

  • execute(expression: string | IScriptExpression, execPath: string, useFromStore?: undefined | false | true): any
  • execute(expression: string | IScriptExpression, execPath: string, environment?: ScriptEnvironment, useFromStore?: undefined | false | true): any
  • Executes the provided expression and returns the result.

    The common script-environment will be used, therefore, method setEnvironment must be called first.

    throws

    Throws in error in case of a compile error or execution error.

    Parameters

    • expression: string | IScriptExpression

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns any

  • Executes the provided expression and returns the result.

    The provided script-environment will be used.

    throws

    Throws in error in case of a compile error or execution error.

    Parameters

    • expression: string | IScriptExpression

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional environment: ScriptEnvironment

      The script-environment to use for this call.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns any

executeBoolean

  • executeBoolean(expression: string, execPath: string, errorValue?: undefined | false | true, useFromStore?: undefined | false | true): boolean
  • executeBoolean(expression: string, execPath: string, environment?: ScriptEnvironment, errorValue?: undefined | false | true, useFromStore?: undefined | false | true): boolean
  • executeBoolean(expression: IScriptExpression, execPath: string, useFromStore?: undefined | false | true): boolean
  • executeBoolean(expression: IScriptExpression, execPath: string, environment?: ScriptEnvironment, useFromStore?: undefined | false | true): boolean
  • Executes the provided expression and tries to convert the result to a boolean. In case of an error, the error-message will be logged and errorValue will be returned.

    The common script-environment will be used, therefore, method setEnvironment must be called first.

    Parameters

    • expression: string

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional errorValue: undefined | false | true

      The value to be returned in case of an error. Default-value: false.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns boolean

  • Executes the provided expression and tries to convert the result to a boolean. In case of an error, the error-message will be logged and errorValue will be returned.

    The provided script-environment will be used.

    Parameters

    • expression: string

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional environment: ScriptEnvironment

      The script-environment to be used for this call.

    • Optional errorValue: undefined | false | true

      The value to be returned in case of an error. Default-value: false.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns boolean

  • Executes the provided expression and tries to convert the result to a boolean. In case of an error, the error-message will be logged and the error-value from the expression will be returned.

    The common script-environment will be used, therefore, method setEnvironment must be called first.

    Parameters

    • expression: IScriptExpression

      The expression to execute. In case of an error, the error-value of expression will be returned. Default-value: false.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns boolean

  • Executes the provided expression and tries to convert the result to a boolean. In case of an error, the error-message will be logged and the error-value from the expression will be returned.

    The provided script-environment will be used.

    Parameters

    • expression: IScriptExpression

      The expression to execute. In case of an error, the error-value of expression will be returned. Default-value: false.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional environment: ScriptEnvironment

      The script-environment to be used for this call.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns boolean

executeNumber

  • executeNumber(expression: string, execPath: string, errorValue?: undefined | number, useFromStore?: undefined | false | true): number
  • executeNumber(expression: string, execPath: string, environment?: ScriptEnvironment, errorValue?: undefined | number, useFromStore?: undefined | false | true): number
  • executeNumber(expression: IScriptExpression, execPath: string, useFromStore?: undefined | false | true): number
  • executeNumber(expression: IScriptExpression, execPath: string, environment?: ScriptEnvironment, useFromStore?: undefined | false | true): number
  • Executes the provided expression and tries to convert the result to a number. In case of an error, the error-message will be logged and errorValue will be returned.

    The common script-environment will be used, therefore, method setEnvironment must be called first.

    Parameters

    • expression: string

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional errorValue: undefined | number

      The value to be returned in case of an error.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns number

  • Executes the provided expression and tries to convert the result to a number. In case of an error, the error-message will be logged and errorValue will be returned.

    The provided script-environment will be used.

    Parameters

    • expression: string

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional environment: ScriptEnvironment

      The script-environment to be used for this call.

    • Optional errorValue: undefined | number

      The value to be returned in case of an error.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns number

  • Executes the provided expression and tries to convert the result to a number. In case of an error, the error-message will be logged and expression.errorValue will be returned. Returns 0, if errorValue is undefined.

    The common script-environment will be used, therefore, method setEnvironment must be called first.

    Parameters

    • expression: IScriptExpression

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns number

  • Executes the provided expression and tries to convert the result to a number. In case of an error, the error-message will be logged and the error-value from the expression will be returned. Returns 0, if errorValue is undefined.

    The provided script-environment will be used.

    Parameters

    • expression: IScriptExpression

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional environment: ScriptEnvironment

      The script-environment to be used for this call.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns number

executeString

  • executeString(expression: string, execPath: string, errorValue?: undefined | string, useFromStore?: undefined | false | true): string
  • executeString(expression: string, execPath: string, environment?: ScriptEnvironment, errorValue?: undefined | string, useFromStore?: undefined | false | true): string
  • executeString(expression: IScriptExpression, execPath: string, useFromStore?: undefined | false | true): string
  • executeString(expression: IScriptExpression, execPath: string, environment?: ScriptEnvironment, useFromStore?: undefined | false | true): string
  • Executes the provided expression and tries to convert the result to a string. In case of an error, the error-message will be logged and errorValue will be returned.

    The common script-environment will be used, therefore, method setEnvironment must be called first.

    Parameters

    • expression: string

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional errorValue: undefined | string

      The value to be returned in case of an error.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns string

  • Executes the provided expression and tries to convert the result to a string. In case of an error, the error-message will be logged and errorValue will be returned.

    The provided script-environment will be used.

    Parameters

    • expression: string

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional environment: ScriptEnvironment

      The script-environment to be used for this call.

    • Optional errorValue: undefined | string

      The value to be returned in case of an error.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns string

  • Executes the provided expression and tries to convert the result to a number. In case of an error, the error-message will be logged and expression.errorValue will be returned. Returns ``, if errorValue is undefined.

    The common script-environment will be used, therefore, method setEnvironment must be called first.

    Parameters

    • expression: IScriptExpression

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns string

  • Executes the provided expression and tries to convert the result to a number. In case of an error, the error-message will be logged and the error-value from the expression will be returned. Returns ``, if errorValue is undefined.

    The provided script-environment will be used.

    Parameters

    • expression: IScriptExpression

      The expression to execute.

    • execPath: string

      A unique key (path to the property), used to identify the expression.

    • Optional environment: ScriptEnvironment

      The script-environment to be used for this call.

    • Optional useFromStore: undefined | false | true

      Stores the expression-tree build at first call for later use. Default-value: true.

    Returns string

Private getCharsFromExpression

  • getCharsFromExpression(expression: string, startIndex: number, whiteList: string): string
  • Parameters

    • expression: string
    • startIndex: number
    • whiteList: string

    Returns string

getLogger

  • returns the logger for this module. Messages are directly written to the console. If you want to use your own library, like loglevel, replace the logging-methods (debug(), info(), error()) with your own methods.

    Returns Logger

hasError

  • hasError(execPath?: undefined | string): number | false | true
  • Returns true, if the execution of the expression belongs to the provided execPath failed since calls. Stays true, until the expression is executed without error.

    Parameters

    • Optional execPath: undefined | string

      The execution-path of the expression. If undefined, returns true if any execution of an expression failed.

    Returns number | false | true

Private isCharInList

  • isCharInList(expression: string, index: number, chars: string): boolean
  • Parameters

    • expression: string
    • index: number
    • chars: string

    Returns boolean

isExpression

  • Returns true, if the provided expression is executable.

    If expression is from type string, expression needs to be surrounded with =[x*y].

    Parameters

    Returns boolean

Private logError

  • logError(path: string, error: Error): void
  • Parameters

    • path: string
    • error: Error

    Returns void

Private logErrorGone

  • logErrorGone(path: string): void
  • Parameters

    • path: string

    Returns void

Private prepareExpression

  • Parameters

    Returns string

setEnvironment

  • Sets the environment (context) used for execution of expression, if an environment is not provided at the exection-methods.

    Parameters

    Returns void

setFunction

  • Adds a new function. Throws an error if adding function failed.

    Parameters

    Returns void

toString

  • toString(): string
  • Returns string

Static GET

  • Returns ScriptEngine

Object literals

Static BOOLEANS

BOOLEANS: object

false

false: boolean = false

true

true: boolean = true

Generated using TypeDoc