joewalnes/filtrex

Expressions with Spaces

Opened this issue · 8 comments

Im trying to get this to parse expressions with spaces e.g. Net Income > 10000. I have tried a few things like wrapping with quotes "Net Income" but that hasn't worked. Any ideas?

Use single quotes:

var e = "'a b' > 3"                                                             
var f = compileExpression(e)                                                    
f({"a b": 1}) // 0                                                              
f({"a b": 4}) // 1

met the same issue, tried using quotes, but it doesn't work, showing: Unrecognized text error

Any advice?

If you want help, show the code that isn't working.

To debug this yourself, open a page that loads filtrex. Then open the javascript console and enter in the code from #14 (comment). Change the expression to match your input and re-test.

I am using the same example you replied @jfinch1991 , the code is as follows:

function hello() {
var e = "'a b' > 3"
var myfilter = compileExpression(e);
myfilter({"a b": 2});
}

Uncaught Error: Lexical error on line 1. Unrecognized text.
'a b' > 3
^

Thanks for advice

Works for me. Try running the tests, in particular check the test for "quoted symbols" passes. To be sure, you can add a test case with whitespace:

diff --git a/test/filtrex-test.html b/test/filtrex-test.html
index d0ba6ed..49a5afe 100644
--- a/test/filtrex-test.html
+++ b/test/filtrex-test.html
@@ -128,6 +128,7 @@ tests({

     'quoted symbols': function() {
         eq(123, compileExpression('\'hello-world-foo\'')({'hello-world-foo': 123}));
+        eq(123, compileExpression('\'hello world foo\'')({'hello world foo': 123}));
         eq(123, compileExpression('\'order+goo*and#stuff\'')({'order+goo*and#stuff': 123}));
     },

If the tests work, verify your version of filtrex.js is up to date.

Thanks for your reply.

I cloned this project and run the tests, all passed. But in my project, I installed filtrex(version: 0.5.4) through npm. When I run the same test('quoted symbol'), it will pop up the errors above. Is the filtrex version in node repository the latest one?

Thanks.

Any updates about the issue?

Thanks

m93a commented

The issue was caused by NPM not being up-to-date. As of 2019 this is no longer the case and the NPM package is being actively maintained again.