import { gt , gte , lt , lte , isNull } from 'lodash' ; export enum Operator { Gte = 'gte' , Lte = 'lte' , Gt = 'gt' , Lt = 'lt' , Empty = 'empty' } export interface Rule { operator : Operator ; value : unknown ; } type OperatorsAllowNullType = { [ name in Operator ] ? : boolean ; } ; const OPERATORS = { [ Operator . Gte ] : gte , [ Operator . Lte ] : lte , [ Operator . Gt ] : gt , [ Operator . Lt ] : lt , [ Operator . Empty ] : isNull , } ; const OPERATORS_ALLOW_NULL = { [ Operator . Empty ] : true , } ; export const getOperator = ( operator ) => { return OPERATORS [ operator ] ; } ; export const shouldOperate = ( rule , value ) => ( isNull ( rule . value ) && OPERATORS_ALLOW_NULL [ rule . operator ] ) || ( ! isNull ( rule . value ) && ! isNull ( value ) ) ;