TomFrost / Jexl

Javascript Expression Language: Powerful context-based expression parser and evaluator
MIT License
561 stars 93 forks source link

Very interesting lib. Can you provide background? #1

Closed d1b1 closed 9 years ago

d1b1 commented 9 years ago

We love your library. We are planning to use this for a project. It would be create for some background on the project or problem that motivated your interest and focus that lead to this?

TomFrost commented 9 years ago

Hey Stephan!

We have a few use cases for this at TechnologyAdvice. As a company our goal is to match businesses up with the technologies they need to complete projects, so we deal with a lot of user profiles and JSON blobs representing clients and products. Jexl's useful for targeting and transforming specific pieces of that data for everything from analytics to suggesting best-match tools that could fit their needs.

To get specific, we have a team of technology advisors, and many of them have areas where they may have more knowledge than others on the team. So if a user requests information from our site, we're more likely to have a happy customer if we can match that person up with the advisor who has the strongest background in that topic. So we'll run new contacts through a list of Jexl expressions (all stored in a database, so we can tweak and update these at any time) to determine their advisor. user.viewedPages[.category == 'crm'].secsOnPage > 300? This person's probably super interested in CRMs and should talk to Cameron about that.

A pattern I've found useful is putting Jexl strings that target certain pieces of info into a table and naming them. So user.transactions[0].date|timeDiff('years') would be mapped to relationshipAge and user.projects.length would be mapped to projectCount. Now advisors can drop those fields into their web interface and they'll pop up when they make a call -- without needing to be familiar with the expression syntax or even that it exists. Similarly, we can use fields like this to target data that should be aggregated in our warehouse, or to show reports at the end of the day.

And those are just the use cases we've thought of so far ;-). Now that we have a more all-encompassing solution, it allows for much more database-determined logic to be defined, rather than pushing code for each new idea or tweak.

Sorry for the drawn-out explanation -- I hope that helps! How are you planning to use it?