logical-phrase
v0.1.3
Published
Logical phrase generator
Downloads
3
Readme
logical-phrase
npm install logical-phrase
# or
bower install logical-phrase
Transforms following JSON:
{
"items": [
{
"value": "foo"
},
{
"value": "bar"
},
{
"value": "baz",
"operator": "NOT"
}
],
"operator": "AND"
}
into:
foo AND bar AND NOT baz
Furthermore, with a given configuration as follows:
var lp = new LogicalPhrase();
lp.configure({
'prefix': 'Select users who',
'truthy': 'did',
'falsy': 'did not',
'and': 'and',
'or': 'or'
});
it can transform this:
{
"items": [
{
"value": "visit 'site.homepage'",
"operator": "NOT"
},
{
"items": [
{
"value": "use campaign 'x'"
},
{
"value": "use campaign 'y'"
}
],
"operator": "OR"
}
],
"operator": "AND"
}
into:
Select users who did not visit 'site.homepage' and did use campaign 'x' or did use campaign 'y'
It is also possible to wrap each level of items into different HTML tags.
See /test for more examples.