Return a deep copy of an object, recursively filtered to have only keys that match the given glob patterns.
Install with npm
npm i deep-filter-object --save
var deepFilter = require('deep-filter-object');
deepFilter({a: 'a', b: {a: 'a', b: {a: 'a', b: 'b', c: 'c'}}}, 'b');
//=> {b: {b: {b: 'b'}}}
deepFilter({foo: 'a', bar: {foo: 'a', bar: {foo: 'a', bar: 'b', baz: 'c'}}}, ['*', '!foo']);
//=> {bar: {bar: {bar: 'b', baz: 'c'}}}
deepFilter({a: 'a', b: 'b', c: 'c'}, function (value, key, obj, i) {
return key === 'b';
});
//=> {b: 'b'}
deepFilter({a: 'a', b: {c: 'c', d: {e: {c: 'c', f: 'f'}}}, c: 'c'}, function (value, key, obj) {
return key !== 'c';
});
//=> {a: 'a', b: {d: {e: {f: 'f'}}}}
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Install dev dependencies:
npm i -d && npm test
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb on January 19, 2015.