filter-type
Filter an array or arguments by JavaScript native type (e.g. functions, strings, etc).
Last updated 11 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install filter-type 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.2.0                                ...           latest (11 years ago)

3 Versions

  • 0.2.0                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |