I have string that have variable conditions in it, like this:
(@IS_VERIFIED = 'True' OR @CONFIRMATION_NEEDED != 'True') AND @REQUEST_LIMIT != '0'
This is just an example and there are unknown number of variables & cases.
- Every variable starts with @
- There are ORs and ANDs with sometimes parenthesis
- Values are always in quotation marks like 'xyz', so all can be considered strings.
- Conditions are always checked with either = or !=
I also have a javascript map which holds all the variables like:
const vars = {
IS_VERIFIED: 'True',
CONFIRMATION_NEEDED: 'True',
REQUEST_LIMIT: '2'
}
What I need to do is parse the condition string and check the values using the map above to reach a final result, true or false. I came up with few ideas but they were all too complicated. Is there any known, easy method for this or do I have to create something from scratch?
Any help is appreciated, thanks.
Edit: After achieving this, next goal for me will be showing which variables break the condition, somehow.
eval, but are you willing to useeval?