Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface OperatorOptions

Defines which operators are allowed.

example
const operatorOptions = {
  unary: { allow: ['!'] },
  binary: { allow: ['+', '-', '*', '/', '%'] },
  logical: { block: ['??'] },
  ternary: false,
}

Hierarchy

  • OperatorOptions

Properties

Optional binary

binary: null | BinaryOperatorOptions

Defines which binary operators are allowed. If defined, must provide an allow list or a block list, but not both. Valid options are +, -, *, **, /, %, <, >, <=, >=, ==, !=, ===, !==, |, &, <<, >>, >>>.

example
// allows only binary operators '/', '%', '+', and '-'
{ binary: { allow: ['/', '%', '+', '-'] } }
// allows any binary operator except '*', '**', and '&'
{ binary: { block: ['*', '**', '&'] } }

Optional logical

logical: null | LogicalOperatorOptions

Defines which logical operators are allowed. If defined, must provide an allow list or a block list, but not both. Valid options are ||, &&, ??.

example
// allows only logical operators '||' and '&&'
{ logical: { allow: ['||', '&&'] } }
// allows any logical operator except '??'
{ logical: { block: ['??'] } }

Optional ternary

ternary: boolean

Whether or not the ternary/conditional operator is allowed. A value of true allows the ternary operator, false blocks it. Defaults to true.

Optional unary

unary: null | UnaryOperatorOptions

Defines which unary operators are allowed. If defined, must provide an allow list or a block list, but not both. Valid options are -, +, !, ~, typeof.

example
// allows only unary operators '!' and '+'
{ unary: { allow: ['!', '+'] } }
// allows any unary operator except '-' and '~'
{ unary: { block: ['-', '~'] } }

Generated using TypeDoc