util-filter

Filter an object, array or string

Usage no npm install needed!

<script type="module">
  import utilFilter from 'https://cdn.skypack.dev/util-filter';
</script>

README

Filter

NPM version Build status Test coverage Gittip

Filter an object, array or string and keep the result as the same type.

Installation

npm install util-filter --save

Usage

var filter = require('util-filter');

// Filter over objects.
filter({
  a: 0,
  b: 1,
  c: 2
}, function (value, key, obj) {
  return value < 2;
});
//=> { a: 0, b: 1 }

// Filter over arrays.
filter(['a', 'b', 'c'], function (value, key, obj) {
  return key % 2;
});
// => ['b']

// Filter over strings.
filter('abc', function (value, key, obj) {
  return true;
});
//=> 'abc'

License

MIT