Function parseCondition

Parses a condition string and returns an object containing a numeric value and its corresponding token expression derived from predefined token mappings.

The condition string should have the format {value/x} {expression} {x/value}, where value should to be number value, and expression like token: ">" | ">=" | "<" | "<=" | "=". It supports conditions where 'x' denotes the variable and the expression determines the comparison to either side.

If x is at the left of the expression, the l_token mapping is used; if on the right, the r_token mapping applies.

> const out = parseCondition("1 < x")
> console.log(out)
{value: 1, expression: "gr"}

Thrown when the condition string does not match the required format.

  • Parameters

    • condition: string

      A string representing the condition to parse.

    Returns { expression: TokenValues; value: number }

    An object containing the numerical value found in the condition and the corresponding token expression.