Monster. Text

Namespace for all text related functions.

Author
  • schukai GmbH

Classes

Formatter

Default values for the markers are ${ and }

.

Methods

(static) generateRangeComparisonExpression(expression, valueName, optionsopt) → {string}

Generates a comparison expression based on a range of values.

The generateRangeComparisonExpression() function is function that generates a string representation of a comparison expression based on a range of values. It takes three arguments:

  • expression (required): a string representation of a range of values in the format of start1-end1,start2-end2,value3....
  • valueName (required): a string representing the name of the value that is being compared to the range of values.
  • options (optional): an object containing additional options to customize the comparison expression.

The generateRangeComparisonExpression() function returns a string representation of the comparison expression.

Options

The options parameter is an object that can have the following properties:

urlEncode (boolean, default: false): if set to true, URL encodes the comparison operators. andOp (string, default: '&&'): the logical AND operator to use in the expression. orOp (string, default: '||'): the logical OR operator to use in the expression. eqOp (string, default: '=='): the equality operator to use in the expression. geOp (string, default: '>='): the greater than or equal to operator to use in the expression. leOp (string, default: '<='): the less than or equal to operator to use in the expression.

Examples

const expression = '0-10,20-30';
const valueName = 'age';
const options = { urlEncode: true, andOp: 'and', orOp: 'or', eqOp: '=', geOp: '>=', leOp: '<=' };
const comparisonExpression = generateRangeComparisonExpression(expression, valueName, options);

console.log(comparisonExpression); // age%3E%3D0%20and%20age%3C%3D10%20or%20age%3E%3D20%20and%20age%3C%3D30

In this example, the generateRangeComparisonExpression() function generates a string representation of the comparison expression for the expression and valueName parameters with the specified options. The resulting comparison expression is 'age>=0 and age<=10 or age>=20 and age<=30', URL encoded according to the urlEncode option.

Parameters:
NameTypeAttributesDescription
expressionstring

The string expression to generate the comparison for.

valueNamestring

The name of the value to compare against.

optionsObject<optional>

The optional parameters.

Properties
NameTypeAttributesDefaultDescription
urlEncodeboolean<optional>
false

Whether to encode comparison operators for use in a URL.

andOpstring<optional>
'&&'

The logical AND operator to use.

orOpstring<optional>
'||'

The logical OR operator to use.

eqOpstring<optional>
'=='

The comparison operator for equality to use.

geOpstring<optional>
'>='

The comparison operator for greater than or equal to to use.

leOpstring<optional>
'<='

The comparison operator for less than or equal to to use.

Throws:

If the input is invalid.

Type
Error
Returns:

The generated comparison expression.

Type: 
string