FunctionUtils class

Utility functions in AdaptiveExpression.

Properties

DefaultDateTimeFormat

The default date time format string.

Methods

apply((arg0: unknown[]) => unknown, VerifyExpression)

Generate an expression delegate that applies function after verifying all children.

applySequence((arg0: any[]) => any, VerifyExpression)

Generate an expression delegate that applies function on the accumulated value after verifying all children.

applySequenceWithError((arg0: any[]) => any, VerifyExpression)

Generate an expression delegate that applies function on the accumulated value after verifying all children.

applyWithError((arg0: any[]) => ValueWithError, VerifyExpression)

Generate an expression delegate that applies function after verifying all children.

applyWithOptions((arg0: unknown[], options: Options) => unknown, VerifyExpression)

Generate an expression delegate that applies function after verifying all children.

applyWithOptionsAndError((arg0: unknown[], options: Options) => { error: string, value: unknown }, VerifyExpression)

Generate an expression delegate that applies function after verifying all children.

commonEquals(unknown, unknown)

Equal helper function. Compare the first param and second param.

determineFormatAndLocale(unknown[], number, string, string)
determineLocale(unknown[], number, string)
evaluateChildren(Expression, MemoryInterface, Options, VerifyExpression)

Evaluate expression children and return them.

isNumber(any)

Is number helper function.

timestampFormatter(string)

Timestamp formatter, convert C# datetime to day.js format.

tryAccumulatePath(Expression, MemoryInterface, Options)

State object for resolving memory paths.

validateArityAndAnyType(Expression, number, number, ReturnType)

Validate that expression has a certain number of children that are of any of the supported types.

validateAtLeastOne(Expression)

Validate at least 1 argument of any type.

validateBinary(Expression)

Validate there are two children.

validateBinaryNumber(Expression)

Validate 2 numeric arguments.

validateBinaryNumberOrString(Expression)

Validate there are 2 numeric or string arguments.

validateNumber(Expression)

Validate 1 or more numeric arguments.

validateOrder(Expression, ReturnType[], ReturnType[])

Validate the number and type of arguments to a function.

validateString(Expression)

Validate 1 or more string arguments.

validateTwoOrMoreThanTwoNumbers(Expression)

Validate 2 or more than 2 numeric arguments.

validateUnary(Expression)

Validate there is a single argument.

validateUnaryBoolean(Expression)

Validate there is a single boolean argument.

validateUnaryNumber(Expression)

Validate there is a single argument.

validateUnaryOrBinaryNumber(Expression)

Validate 1 or 2 numeric arguments.

validateUnaryOrBinaryString(Expression)

Validate there is one or two string arguments.

validateUnaryString(Expression)

Validate there is a single string argument.

verifyBoolean(any, Expression, number)

Verify value is boolean.

verifyContainer(any, Expression, number)

Verify value contains elements.

verifyContainerOrNull(unknown, Expression, number)

Verify value contains elements or null.

verifyInteger(any, Expression, number)

Verify value is an integer.

verifyList(any, Expression)

Verify value is an list.

verifyNotNull(any, Expression, number)

Verify value is not null or undefined.

verifyNumber(any, Expression, number)

Verify value is numeric.

verifyNumberOrNumericList(any, Expression, number)

Verify value is numeric.

verifyNumberOrString(any, Expression, number)

Verify value is a number or string.

verifyNumberOrStringOrNull(any, Expression, number)

Verify value is a number or string or null.

verifyNumericList(any, Expression, number)

Verify value is numeric list.

verifyString(any, Expression, number)

Verify value is a string.

verifyStringOrNull(any, Expression, number)

Verify an object is neither a string nor null.

Property Details

DefaultDateTimeFormat

The default date time format string.

static DefaultDateTimeFormat: string = "YYYY-MM-DDTHH:mm:ss.SSS[Z]"

Property Value

string

Method Details

apply((arg0: unknown[]) => unknown, VerifyExpression)

Generate an expression delegate that applies function after verifying all children.

static function apply(func: (arg0: unknown[]) => unknown, verify?: VerifyExpression): EvaluateExpressionDelegate

Parameters

func

(arg0: unknown[]) => unknown

Function to apply.

verify
VerifyExpression

Function to check each arg for validity.

Returns

Delegate for evaluating an expression.

applySequence((arg0: any[]) => any, VerifyExpression)

Generate an expression delegate that applies function on the accumulated value after verifying all children.

static function applySequence(func: (arg0: any[]) => any, verify?: VerifyExpression): EvaluateExpressionDelegate

Parameters

func

(arg0: any[]) => any

Function to apply.

verify
VerifyExpression

Function to check each arg for validity.

Returns

Delegate for evaluating an expression.

applySequenceWithError((arg0: any[]) => any, VerifyExpression)

Generate an expression delegate that applies function on the accumulated value after verifying all children.

static function applySequenceWithError(func: (arg0: any[]) => any, verify?: VerifyExpression): EvaluateExpressionDelegate

Parameters

func

(arg0: any[]) => any

Function to apply.

verify
VerifyExpression

Function to check each arg for validity.

Returns

Delegate for evaluating an expression.

applyWithError((arg0: any[]) => ValueWithError, VerifyExpression)

Generate an expression delegate that applies function after verifying all children.

static function applyWithError(func: (arg0: any[]) => ValueWithError, verify?: VerifyExpression): EvaluateExpressionDelegate

Parameters

func

(arg0: any[]) => ValueWithError

Function to apply.

verify
VerifyExpression

Function to check each arg for validity.

Returns

Delegate for evaluating an expression.

applyWithOptions((arg0: unknown[], options: Options) => unknown, VerifyExpression)

Generate an expression delegate that applies function after verifying all children.

static function applyWithOptions(func: (arg0: unknown[], options: Options) => unknown, verify?: VerifyExpression): EvaluateExpressionDelegate

Parameters

func

(arg0: unknown[], options: Options) => unknown

Function to apply.

verify
VerifyExpression

Function to check each arg for validity.

Returns

Delegate for evaluating an expression.

applyWithOptionsAndError((arg0: unknown[], options: Options) => { error: string, value: unknown }, VerifyExpression)

Generate an expression delegate that applies function after verifying all children.

static function applyWithOptionsAndError(func: (arg0: unknown[], options: Options) => { error: string, value: unknown }, verify?: VerifyExpression): EvaluateExpressionDelegate

Parameters

func

(arg0: unknown[], options: Options) => { error: string, value: unknown }

Function to apply.

verify
VerifyExpression

Function to check each arg for validity.

Returns

Delegate for evaluating an expression.

commonEquals(unknown, unknown)

Equal helper function. Compare the first param and second param.

static function commonEquals(obj1: unknown, obj2: unknown): boolean

Parameters

obj1

unknown

The first value to compare.

obj2

unknown

The second value to compare.

Returns

boolean

A boolean based on the comparison.

determineFormatAndLocale(unknown[], number, string, string)

static function determineFormatAndLocale(args: unknown[], maxArgsLength: number, format: string, locale: string): { format: string, locale: string }

Parameters

args

unknown[]

An array of arguments.

maxArgsLength

number

The max length of a given function.

format

string

A format string.

locale

string

A locale string.

Returns

{ format: string, locale: string }

The format and the locale from the args param, otherwise the locale and format strings.

determineLocale(unknown[], number, string)

static function determineLocale(args: unknown[], maxArgsLength: number, locale: string): string

Parameters

args

unknown[]

An array of arguments.

maxArgsLength

number

The max length of a given function.

locale

string

A locale string

Returns

string

The last item from the args param, otherwise the locale string.

evaluateChildren(Expression, MemoryInterface, Options, VerifyExpression)

Evaluate expression children and return them.

static function evaluateChildren(expression: Expression, state: MemoryInterface, options: Options, verify?: VerifyExpression): { args: any[], error: string }

Parameters

expression
Expression

Expression with children.

state
MemoryInterface

Global state.

options
Options

Options used in evaluation.

verify
VerifyExpression

Optional function to verify each child's result.

Returns

{ args: any[], error: string }

List of child values or error message.

isNumber(any)

Is number helper function.

static function isNumber(instance: any): boolean

Parameters

instance

any

Input.

Returns

boolean

True if the input is a number.

timestampFormatter(string)

Timestamp formatter, convert C# datetime to day.js format.

static function timestampFormatter(formatter: string): string

Parameters

formatter

string

C# datetime format

Returns

string

The formated datetime.

tryAccumulatePath(Expression, MemoryInterface, Options)

State object for resolving memory paths.

static function tryAccumulatePath(expression: Expression, state: MemoryInterface, options: Options): { error: string, left: any, path: string }

Parameters

expression
Expression

Expression.

state
MemoryInterface

Scope.

options
Options

Options used in evaluation.

Returns

{ error: string, left: any, path: string }

Return the accumulated path and the expression left unable to accumulate.

validateArityAndAnyType(Expression, number, number, ReturnType)

Validate that expression has a certain number of children that are of any of the supported types.

static function validateArityAndAnyType(expression: Expression, minArity: number, maxArity: number, returnType: ReturnType)

Parameters

expression
Expression

Expression to validate.

minArity

number

Minimum number of children.

maxArity

number

Maximum number of children.

returnType
ReturnType

Allowed return types for children. If a child has a return type of Object then validation will happen at runtime.

validateAtLeastOne(Expression)

Validate at least 1 argument of any type.

static function validateAtLeastOne(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateBinary(Expression)

Validate there are two children.

static function validateBinary(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateBinaryNumber(Expression)

Validate 2 numeric arguments.

static function validateBinaryNumber(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateBinaryNumberOrString(Expression)

Validate there are 2 numeric or string arguments.

static function validateBinaryNumberOrString(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateNumber(Expression)

Validate 1 or more numeric arguments.

static function validateNumber(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateOrder(Expression, ReturnType[], ReturnType[])

Validate the number and type of arguments to a function.

static function validateOrder(expression: Expression, optional: ReturnType[], types: ReturnType[])

Parameters

expression
Expression

Expression to validate.

optional

ReturnType[]

Optional types in order.

types

ReturnType[]

Expected types in order.

validateString(Expression)

Validate 1 or more string arguments.

static function validateString(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateTwoOrMoreThanTwoNumbers(Expression)

Validate 2 or more than 2 numeric arguments.

static function validateTwoOrMoreThanTwoNumbers(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateUnary(Expression)

Validate there is a single argument.

static function validateUnary(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateUnaryBoolean(Expression)

Validate there is a single boolean argument.

static function validateUnaryBoolean(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateUnaryNumber(Expression)

Validate there is a single argument.

static function validateUnaryNumber(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateUnaryOrBinaryNumber(Expression)

Validate 1 or 2 numeric arguments.

static function validateUnaryOrBinaryNumber(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateUnaryOrBinaryString(Expression)

Validate there is one or two string arguments.

static function validateUnaryOrBinaryString(expression: Expression)

Parameters

expression
Expression

Expression to validate.

validateUnaryString(Expression)

Validate there is a single string argument.

static function validateUnaryString(expression: Expression)

Parameters

expression
Expression

Expression to validate.

verifyBoolean(any, Expression, number)

Verify value is boolean.

static function verifyBoolean(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyContainer(any, Expression, number)

Verify value contains elements.

static function verifyContainer(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyContainerOrNull(unknown, Expression, number)

Verify value contains elements or null.

static function verifyContainerOrNull(value: unknown, expression: Expression, _: number): string | undefined

Parameters

value

unknown

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyInteger(any, Expression, number)

Verify value is an integer.

static function verifyInteger(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyList(any, Expression)

Verify value is an list.

static function verifyList(value: any, expression: Expression): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

Returns

string | undefined

Error or undefined if invalid.

verifyNotNull(any, Expression, number)

Verify value is not null or undefined.

static function verifyNotNull(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if valid.

verifyNumber(any, Expression, number)

Verify value is numeric.

static function verifyNumber(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyNumberOrNumericList(any, Expression, number)

Verify value is numeric.

static function verifyNumberOrNumericList(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyNumberOrString(any, Expression, number)

Verify value is a number or string.

static function verifyNumberOrString(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyNumberOrStringOrNull(any, Expression, number)

Verify value is a number or string or null.

static function verifyNumberOrStringOrNull(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyNumericList(any, Expression, number)

Verify value is numeric list.

static function verifyNumericList(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyString(any, Expression, number)

Verify value is a string.

static function verifyString(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.

verifyStringOrNull(any, Expression, number)

Verify an object is neither a string nor null.

static function verifyStringOrNull(value: any, expression: Expression, _: number): string | undefined

Parameters

value

any

Value to check.

expression
Expression

Expression that led to value.

_

number

No function.

Returns

string | undefined

Error or undefined if invalid.