Content Length Logic Condition (#63)

This commit is contained in:
Chirag
2023-01-21 17:28:01 +05:30
committed by GitHub
parent 970893329b
commit e073ca02a8
4 changed files with 267 additions and 1 deletions

View File

@@ -159,6 +159,25 @@ function checkNextYear (condition, fieldValue) {
return (fieldDate >= today && fieldDate <= new Date(today.getFullYear() + 1, today.getMonth(), today.getDate()))
}
function checkLength (condition, fieldValue, operator = '===') {
if(!fieldValue || fieldValue.length === 0) return false;
switch (operator) {
case '===':
return fieldValue.length === parseInt(condition.value)
case '!==':
return fieldValue.length !== parseInt(condition.value)
case '>':
return fieldValue.length > parseInt(condition.value)
case '>=':
return fieldValue.length >= parseInt(condition.value)
case '<':
return fieldValue.length < parseInt(condition.value)
case '<=':
return fieldValue.length <= parseInt(condition.value)
}
return false
}
function textConditionMet (propertyCondition, value) {
switch (propertyCondition.operator) {
case 'equals':
@@ -177,6 +196,18 @@ function textConditionMet (propertyCondition, value) {
return checkIsEmpty(propertyCondition, value)
case 'is_not_empty':
return !checkIsEmpty(propertyCondition, value)
case 'content_length_equals':
return checkLength(propertyCondition, value, '===')
case 'content_length_does_not_equal':
return checkLength(propertyCondition, value, '!==')
case 'content_length_greater_than':
return checkLength(propertyCondition, value, '>')
case 'content_length_greater_than_or_equal_to':
return checkLength(propertyCondition, value, '>=')
case 'content_length_less_than':
return checkLength(propertyCondition, value, '<')
case 'content_length_less_than_or_equal_to':
return checkLength(propertyCondition, value, '<=')
}
return false
}
@@ -198,7 +229,19 @@ function numberConditionMet (propertyCondition, value) {
case 'is_empty':
return checkIsEmpty(propertyCondition, value)
case 'is_not_empty':
return !checkIsEmpty(propertyCondition, value)
return checkIsEmpty(propertyCondition, value)
case 'content_length_equals':
return checkLength(propertyCondition, value, '===')
case 'content_length_does_not_equal':
return checkLength(propertyCondition, value, '!==')
case 'content_length_greater_than':
return checkLength(propertyCondition, value, '>')
case 'content_length_greater_than_or_equal_to':
return checkLength(propertyCondition, value, '>=')
case 'content_length_less_than':
return checkLength(propertyCondition, value, '<')
case 'content_length_less_than_or_equal_to':
return checkLength(propertyCondition, value, '<=')
}
return false
}