Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

deep-filter-object

1.0.0 • Public • Published

deep-filter-object NPM version

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

Usage

var deepFilter = require('deep-filter-object');
 
deepFilter({a: 'a', b: {a: 'a', b: {a: 'a', b: 'b', c: 'c'}}}, 'b');
//=> {b: {b: {b: 'b'}}}

Negation patterns:

deepFilter({foo: 'a', bar: {foo: 'a', bar: {foo: 'a', bar: 'b', baz: 'c'}}}, ['*', '!foo']);
//=> {bar: {bar: {bar: 'b', baz: 'c'}}}

Filter functions

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'}}}}

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Run tests

Install dev dependencies:

npm i -d && npm test

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb on January 19, 2015.

Install

npm i deep-filter-object

DownloadsWeekly Downloads

50

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar