generateRangeComparisonExpression

This documentation describes the generateRangeComparisonExpression function, its parameters, return value, and an example usage.

generateRangeComparisonExpression(expression, valueName, options = {}) generates a comparison expression for a comma-separated string of ranges and single values.

Parameters

  • expression (string): The string expression containing comma-separated ranges and single values to generate the comparison for.
  • valueName (string): The name of the value to compare against in the generated expression.
  • options (Object, optional): The optional parameters for the function. Defaults to an empty object.
  • urlEncode (boolean, optional): Whether to encode comparison operators for use in a URL. Defaults to false.
  • andOp (string, optional): The logical AND operator to use. Defaults to ‘&&’.
  • orOp (string, optional): The logical OR operator to use. Defaults to ‘||’.
  • eqOp (string, optional): The comparison operator for equality to use. Defaults to ‘==’.
  • geOp (string, optional): The comparison operator for greater than or equal to use. Defaults to ‘>=’.
  • leOp (string, optional): The comparison operator for less than or equal to use. Defaults to ‘<’.

Returns

(string): The generated comparison expression.

Throws

Error: If the input expression contains invalid ranges or values.

Example

const expression = "1,3,5-7";
const valueName = "x";
const comparisonExpression = generateRangeComparisonExpression(expression, valueName);
console.log(comparisonExpression); // "(x==1) || (x==3) || (x>=5 && x<=7)"