filter-object
Advanced tools
Comparing version
@@ -19,15 +19,22 @@ # {%= name %} {%= badge("fury") %} | ||
filter({a: 'a', b: 'b', c: 'c'}, '*') | ||
filter({a: 'a', b: 'b', c: 'c'}, '*'); | ||
//=> {a: 'a', b: 'b', c: 'c'} | ||
filter({a: 'a', b: 'b', c: 'c'}, 'b') | ||
filter({a: 'a', b: 'b', c: 'c'}, 'b'); | ||
//=> {b: 'b'} | ||
filter({foo: 'a', bar: 'b', baz: 'c'}, 'b*') | ||
filter({foo: 'a', bar: 'b', baz: 'c'}, 'b*'); | ||
//=> {bar: 'b', baz: 'c'} | ||
filter({a: 'a', b: 'b', c: 'c'}, '{b,c}') | ||
filter({a: 'a', b: 'b', c: 'c'}, '{b,c}'); | ||
//=> {b: 'b', c: 'c'} | ||
``` | ||
Negation patterns work as well: | ||
```js | ||
filter({foo: 'a', bar: 'b', baz: 'c'}, ['*', '!b*']); | ||
//=> {foo: 'a'} | ||
``` | ||
## Contributing | ||
@@ -34,0 +41,0 @@ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue][issues]. |
{ | ||
"name": "filter-object", | ||
"description": "Return an object filtered to have only the keys that match the given glob patterns.", | ||
"version": "0.1.1", | ||
"description": "Return a copy of an object, filtered to have only keys that match the given glob patterns.", | ||
"version": "0.1.3", | ||
"homepage": "https://github.com/jonschlinkert/filter-object", | ||
@@ -35,8 +35,32 @@ "author": { | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"arr", | ||
"array", | ||
"expand", | ||
"filter", | ||
"find", | ||
"function", | ||
"glob", | ||
"globbing", | ||
"globs", | ||
"js", | ||
"key", | ||
"keys", | ||
"match", | ||
"matcher", | ||
"minimatch", | ||
"obj", | ||
"object", | ||
"order", | ||
"pattern", | ||
"patterns", | ||
"sort", | ||
"util", | ||
"utility", | ||
"wildcard" | ||
], | ||
"dependencies": { | ||
"filter-keys": "^0.1.1", | ||
"multimatch": "^1.0.0", | ||
"sort-object": "^0.3.1" | ||
} | ||
} | ||
} |
# filter-object [](http://badge.fury.io/js/filter-object) | ||
> Return an object filtered to have only the keys that match the given glob patterns. | ||
> Return a copy of an object, filtered to have only keys that match the given glob patterns. | ||
@@ -23,15 +23,22 @@ ## Install | ||
filter({a: 'a', b: 'b', c: 'c'}, '*') | ||
filter({a: 'a', b: 'b', c: 'c'}, '*'); | ||
//=> {a: 'a', b: 'b', c: 'c'} | ||
filter({a: 'a', b: 'b', c: 'c'}, 'b') | ||
filter({a: 'a', b: 'b', c: 'c'}, 'b'); | ||
//=> {b: 'b'} | ||
filter({foo: 'a', bar: 'b', baz: 'c'}, 'b*') | ||
filter({foo: 'a', bar: 'b', baz: 'c'}, 'b*'); | ||
//=> {bar: 'b', baz: 'c'} | ||
filter({a: 'a', b: 'b', c: 'c'}, '{b,c}') | ||
filter({a: 'a', b: 'b', c: 'c'}, '{b,c}'); | ||
//=> {b: 'b', c: 'c'} | ||
``` | ||
Negation patterns work as well: | ||
```js | ||
filter({foo: 'a', bar: 'b', baz: 'c'}, ['*', '!b*']); | ||
//=> {foo: 'a'} | ||
``` | ||
## Contributing | ||
@@ -38,0 +45,0 @@ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue][issues]. |
@@ -21,2 +21,7 @@ /*! | ||
it('should exclude keys that match negation patterns:', function () { | ||
filter({a: 'a', b: 'b', c: 'c'}, ['*', '!a']).should.eql({b: 'b', c: 'c'}); | ||
filter({foo: 'a', bar: 'b', baz: 'c'}, ['*', '!b*']).should.eql({foo: 'a'}); | ||
}); | ||
it('should filter keys using brace expansion', function () { | ||
@@ -23,0 +28,0 @@ filter({a: 'a', b: 'b', c: 'c'}, '{b,c}').should.eql({b: 'b', c: 'c'}); |
7376
11.93%2
-33.33%44
10%61
12.96%- Removed