Skip to content

Latest commit

 

History

History
72 lines (62 loc) · 1.13 KB

README.md

File metadata and controls

72 lines (62 loc) · 1.13 KB

objglob

Run glob-like patterns against JavaScript objects

A simple recursive wrapper around https://github.com/isaacs/minimatch

Use

Like this

var filter = require('objglob').filter;
var result = filter(['pattern/**', 'globs'], inputObject);

The objective is to take something like this:

{
    "name":"root",
    "_attr": {
        "id":"x"
    },

    "link": [
        {
            "type":"A",
            "child": {
                "name":"a-child",
                "class":"beta"
            }
        },
        {
            "type":"B",
            "child": {
                "_attr": {
                    "id":"y",
                    "name":"identifier"
                },
                "name":"b-child",
                "class":"beta"
            }
        }
    ]
}

and apply a script to it like this:

!**/_attr
**/name

then end up with

{
    "name":"root",
    "link": [
        {
            "child": {
                "name":"a-child",
            }
        },
        {
            "child": {
                "name":"b-child",
            }
        }
    ]
}