joewalnes / filtrex

A simple, safe, JavaScript Filter Expression compiler for end-users
MIT License
1.05k stars 74 forks source link

Allow json params #29

Closed arvigeus closed 5 years ago

arvigeus commented 5 years ago
const expression = 'answer.index > 1 ? "Yes" : "No"';

const myfilter = filtrex(expression);

// Execute function
console.log(myfilter({ answer: { index: 2 } })); // returns "No"
cshaa commented 5 years ago

Right now Filtrex takes . as a part of the identifier, so this would work:

console.log(myfilter({ 'answer.index': 2 })); // returns "Yes"

In my fork I've implemented an of operator – you'd use it like so:

const expression = 'index of answer > 1 ? "Yes" : "No"';

const myfilter = filtrex(expression);

// Execute function
console.log(myfilter({ answer: { index: 2 } })); // returns "Yes"
cshaa commented 5 years ago

Version 1.0.0 that was published today on the official NPM supports the of operator, so you can use that. Would you please close this issue, I don't have moderator rights here 😅