Not a Propaganda Machine
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    strainerpublic

    strainer

    Simple filtering of arrays and object streams.

    Installation

    npm install strainer

    Basic Use (Stream)

    [
        {"bar": "foo"},
        {"foo": "bar"}
    ]
    var strainer    = require('strainer');
    var input       = require('fs').createReadStream('/some/array.json');
     
    input.pipe(strainer({
        key:    'foo',
        value:  'bar'
    })).pipe(process.stdout);

    Basic Use (Array / Callback)

    var strainer    = require('strainer');
    var input       = [{'bar':'foo'}, {'foo':'bar'}];
     
    strainer({
        input:  someArray,
        key:    'foo',
        value:  'bar'
    }, function (err, result) {
        // Yay! 
    });

    Using Functions as Values

    If a function is provided as the "value" attribute, it will be used as a subroutine to evaluate each object. For example:

    var strainer    = require('strainer');
    var someArray   = [{foo: 1}, {foo: 2}, {foo: 3}, {foo: 4}];
     
    strainer({
        input:  someArray,
        key:    'foo',
        value:  function (val) {
            return val > 2;
        }
    }, function (err, result) {
        // [{foo: 3}, {foo: 4}] 
    });

    Selectors

    Strainer supports the use of JS-style object selectors. For example, let's say you had a complex object:

    [
        {
            "level1": {
                "id": "something",
                "stuff": []
            },
            "level2": {
                "id": "somethingElse",
                "stuff": [
                    {
                        "prop": true
                    },
                    {
                        "prop": false
                    }
                ]
            }
        }
    ]

    Here, you could use a selector to filter out a property that is buried deep within each object:

    input.pipe(strainer({
        key:    'level2.stuff[0].prop',
        value:  true
    })).pipe(process.stdout);

    Testing

    npm test

    Naïve Benchmarks

    make benchmark

    Keywords

    none

    install

    npm i strainer

    Downloadslast 7 days

    2

    version

    0.1.0

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar