filter-type
v0.2.0 args arguments array filter javascript native type typeof util and 4 more...
filter-type
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 filtertype
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 acallback
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.
npm i filter-type
Metadata
- [object Object]
- >=0.10.0
- Jon Schlinkert
- released 3/22/2015