boolean-json-prune

1.1.1 • Public • Published

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"

Package Sidebar

Install

npm i boolean-json-prune

Weekly Downloads

1

Version

1.1.1

License

MIT

Last publish

Collaborators

  • robertherhold