This package cleans up boolean-json expressions.
const prune = require('boolean-json-prune');
const input = {
and: [{
or: [{
and: [{
and: ['foo', 'bar']
}, {
and: ['foo2', 'bar2']
}]
}, {
or: ['foo3', 'bar4']
}]
}, 'foo4']
};
const output = prune(input);
/*
{
and: [{
or: [{
and: ['foo', 'bar', 'foo2', 'bar2']
}, 'foo3', 'bar4']
}, 'foo4']
}
*/
Note: any combination of these operations is also possible.
Input:
{
"and": ["foo", "bar", {
"and": ["baz", "foo2"]
}]
}
Output:
{
"and": ["foo", "bar", "baz", "foo2"]
}
Input:
{
"and": ["foo", "foo", "bar"]
}
Output:
{
"and": ["foo", "bar"]
}
Input:
{
"or": ["foo", {
"and": ["foo", "bar", "baz"]
}]
}
Output:
"foo"
Input:
{
"and": ["foo", {
"or": ["foo", "bar", "baz"]
}]
}
Output:
"foo"