boolean-json-prune
v1.1.1
Published
Prune boolean JSON expressions
Downloads
9
Maintainers
Readme
boolean-json-prune
This package cleans up boolean-json expressions.
Usage
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']
}
*/
Operations
Note: any combination of these operations is also possible.
Combining nested conjunctions/disjunctions
Input:
{
"and": ["foo", "bar", {
"and": ["baz", "foo2"]
}]
}
Output:
{
"and": ["foo", "bar", "baz", "foo2"]
}
Removing duplicates
Input:
{
"and": ["foo", "foo", "bar"]
}
Output:
{
"and": ["foo", "bar"]
}
Removing redundant nested conjunctions/disjunctions
Input:
{
"or": ["foo", {
"and": ["foo", "bar", "baz"]
}]
}
Output:
"foo"
Input:
{
"and": ["foo", {
"or": ["foo", "bar", "baz"]
}]
}
Output:
"foo"