-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expressions to customise return value #26
Comments
Hi! Let me know if this fixed your issue 😁️ |
What a neat library. While I have you, what's the best way to compare a part of the data against time with this? customprop a timestamp or date object?? Couldn't figure out what I need to do to this
Thanks!! |
I'm not sure I understand your question. Do you want to find a user-friendly way to choose the cutoff date? Something like function date(str) { your implementation }
let options = {
extraFunctions: { date }
};
let myfilter = compileExpression('timestamp of data > date("2020-21-01")', options);
myfilter({data : { timestamp: 4543623626 }}); Or you just want to pass more data to the expression? The simplest way would be to pass the data the intended way: function supplyTimestamp(){ your implementation }
let myfilter = compileExpression('timestamp of data > _timestamp');
myfilter({
data : { timestamp: 4543623626 },
_timestamp: suplyTimestamp(),
/* or alternatively */
get _timestamp() { return suplyTimestamp() }
}); If you didn't like this for some reason, custom function customProp(name, get) {
if (name === '_timestamp') return supplyTimestamp()
else return get(name)
}
let options = { customProp };
let myfilter = compileExpression('timestamp of data > _timestamp', options);
myfilter({data : { timestamp: 4543623626 }}); |
Love this solution thanks. Is there a reason why you return 1 and 0 for conditional expressions rather than a boolean? booleans would be great to better confirm that the expression entered is a conditional type of expression. |
The decission to use only numbers and strings was made at the very beginning of filtrex to make matters as simple as they can possibly be. (Since then arrays and objects also appeared.) However, you are right that from the user's perspective, it doesn't necessarily make sense that |
Is there scope in this project to allow expressions that calculate a return value?
The text was updated successfully, but these errors were encountered: