joewalnes / filtrex

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

Allow date data types? #13

Open ghost opened 8 years ago

ghost commented 8 years ago

I need your library for parsing expressions but I saw that it only supports numbers and strings. Is it possible to somehow allow date manipulation? The expression I need to parse is:

'31.07.' + (myDate.getMonth() <= 7 ? myDate.getFullYear() + 3: myDate.getFullYear() + 4 )

cshaa commented 6 years ago

You can define your custom functions for it:

let filter = compileExpression(
  '"31.07." + (month(myDate) <= 7 ? year(myDate) + 3 : year(myDate) + 4)',
  {
    month: date => date.getMonth(),
    year: date => date.getFullYear()
  }
);

filter({myDate: new Date()});
cshaa commented 5 years ago

@joewalnes Close this?