filter-values
Advanced tools
Comparing version 0.2.0 to 0.3.0
25
index.js
@@ -9,4 +9,3 @@ /*! | ||
var forOwn = require('for-own'); | ||
var iterator = require('make-iterator'); | ||
var mm = require('micromatch'); | ||
var matcher = require('is-match'); | ||
@@ -18,12 +17,13 @@ /** | ||
* @param {Object} `obj` | ||
* @param {Function|Array|String} `filter` | ||
* @param {Object} `thisArg` | ||
* @param {Function|Array|String|RegExp} `filter` | ||
* @param {Object} `options` pass options to `micromatch` | ||
* @return {Object} | ||
*/ | ||
module.exports = function filterValues(obj, filter, thisArg) { | ||
var cb = matcher(filter, thisArg); | ||
module.exports = function filterValues(obj, filter, options) { | ||
var isMatch = matcher(filter, options); | ||
var res = {}; | ||
forOwn(obj, function (val, key, o) { | ||
if (cb(val, key, o)) { | ||
forOwn(obj, function (val, key) { | ||
if (isMatch(val)) { | ||
res[key] = val; | ||
@@ -34,10 +34,1 @@ } | ||
}; | ||
function matcher(filter, thisArg) { | ||
if (Array.isArray(filter) || typeof filter === 'string') { | ||
return function (val) { | ||
return !!mm(val, filter).length; | ||
}; | ||
} | ||
return iterator(filter, thisArg) | ||
} |
{ | ||
"name": "filter-values", | ||
"description": "Filter an object values using glob patterns or with a `callback` function returns true. ", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/jonschlinkert/filter-values", | ||
"author": { | ||
"name": "Jon Schlinkert", | ||
"url": "https://github.com/jonschlinkert" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jonschlinkert/filter-values.git" | ||
}, | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"repository": "jonschlinkert/filter-values", | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/filter-values/issues" | ||
}, | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/filter-values/blob/master/LICENSE" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
@@ -31,2 +22,6 @@ "index.js" | ||
}, | ||
"dependencies": { | ||
"for-own": "^0.1.3", | ||
"is-match": "^0.2.0" | ||
}, | ||
"devDependencies": { | ||
@@ -58,3 +53,14 @@ "mocha": "*", | ||
"wildcard" | ||
] | ||
], | ||
"verb": { | ||
"related": { | ||
"list": [ | ||
"filter-object", | ||
"filter-values", | ||
"micromatch", | ||
"rename-keys", | ||
"sort-object" | ||
] | ||
} | ||
} | ||
} |
@@ -1,9 +0,9 @@ | ||
# filter-values [![NPM version](https://badge.fury.io/js/filter-values.svg)](http://badge.fury.io/js/filter-values) [![Build Status](https://travis-ci.org/jonschlinkert/filter-values.svg)](https://travis-ci.org/jonschlinkert/filter-values) | ||
# filter-values [![NPM version](https://badge.fury.io/js/filter-values.svg)](http://badge.fury.io/js/filter-values) [![Build Status](https://travis-ci.org/jonschlinkert/filter-values.svg)](https://travis-ci.org/jonschlinkert/filter-values) | ||
> Filter an object values using glob patterns or with a `callback` function returns true. | ||
> Filter an object values using glob patterns or with a `callback` function returns true. | ||
## Install with [npm](npmjs.org) | ||
Install with [npm](https://www.npmjs.com/) | ||
```bash | ||
npm i filter-values --save | ||
```sh | ||
$ npm i filter-values --save | ||
``` | ||
@@ -21,3 +21,2 @@ | ||
filter({a: 'a', b: 'b', c: 'c'}, function(value, key, obj) { | ||
@@ -41,18 +40,20 @@ return key === 'b'; | ||
## Related | ||
* [filter-object](https://github.com/jonschlinkert/filter-object): Return a copy of an object, filtered to have only keys that match the given glob patterns. | ||
* [filter-values](https://github.com/jonschlinkert/filter-values): Filter an object to have only the `own` properties for which a `callback` function returns true. | ||
* [micromatch](https://github.com/jonschlinkert/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just use `micromatch.isMatch()` instead of `minimatch()`, or use `micromatch()` instead of `multimatch()`. | ||
* [rename-keys](https://github.com/jonschlinkert/rename-keys): Modify the names of the own enumerable properties (keys) of an object. | ||
* [sort-object](https://github.com/doowb/sort-object): Sort the keys in an object. | ||
* [filter-object](https://github.com/jonschlinkert/filter-object): Return a copy of an object, filtered to have only keys that match the given… [more](https://github.com/jonschlinkert/filter-object) | ||
* [micromatch](https://github.com/jonschlinkert/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://github.com/jonschlinkert/micromatch) | ||
* [rename-keys](https://github.com/jonschlinkert/rename-keys): Modify the names of the own enumerable properties (keys) of an object. | ||
* [sort-object](https://github.com/doowb/sort-object): Sort the keys in an object. | ||
## Running tests | ||
Install dev dependencies: | ||
```bash | ||
npm i -d && npm test | ||
```sh | ||
$ npm i -d && npm test | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/filter-values/issues) | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/filter-values/issues/new) | ||
## Author | ||
@@ -63,10 +64,11 @@ | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
Copyright © 2014-2015 [Jon Schlinkert](https://github.com/jonschlinkert) | ||
Released under the MIT license. | ||
*** | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 31, 2015._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on July 13, 2015._ |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
72
5224
2
27
1
+ Addedfor-own@^0.1.3
+ Addedis-match@^0.2.0
+ Addedarr-diff@2.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarray-unique@0.2.1(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextglob@0.3.2(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-match@0.2.0(transitive)
+ Addedis-number@2.1.04.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.0(transitive)
+ Addedkind-of@3.2.26.0.3(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.11(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)