0.2.0 • Published 9 years ago

filter-type v0.2.0

Weekly downloads
55
License
MIT
Repository
github
Last release
9 years ago

filter-type NPM version Build Status

Filter an array or arguments by JavaScript native type (e.g. functions, strings, etc).

Install with npm

npm i filter-type --save

Usage

var filter = require('filter-type');
filter(array, type);

Params

  • array The array to filter
  • type Native JavaScript type to filter by (e.g. string, function etc)

Example

var arr = [1, 'a', {aaa: 'bbb'}, 3, 'b', 'c', 7, ['foo', 'bar'], function one(){}];

filter(arr, 'object');
//=> [{aaa: 'bbb'}]

filter(arr, 'array');
//=> [['foo', 'bar']]

filter(arr, 'number');
//=> [1, 3, 7]

filter(arr, 'string');
//=> ['a', 'b', 'c']

filter(arr, 'function');
//=> [function one(){}]

Similar projects

  • kind-of: Get the native type of a value.
  • filter-keys: Filter the keys of an object using glob patterns.
  • filter-object: Return a copy of an object, filtered to have only keys that match the given glob patterns.
  • filter-values: Filter an object to have only the own properties for which a callback function returns true.

Running tests

Install dev dependencies.

npm i -d && npm test

Contributing

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

Author

Jon Schlinkert

License

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


This file was generated by verb-cli on March 22, 2015.