Skip to content

Latest commit

 

History

History
114 lines (86 loc) · 1.53 KB

README.md

File metadata and controls

114 lines (86 loc) · 1.53 KB

boolean-json-prune

NPM

Build Status

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"