From 3b9882680fe486a229f16d8e2328f2af86ed97ef Mon Sep 17 00:00:00 2001 From: pushpinder107 Date: Tue, 8 May 2018 02:40:03 +0530 Subject: [PATCH] fix: issue with filtering with property values of number 0 (#47) * Fixes issue with filtering with property values of number 0 * Fixes null check * Update index.js --- .all-contributorsrc | 9 +++++++++ README.md | 4 ++-- src/__tests__/index.js | 13 +++++++++++++ src/index.js | 3 ++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 354d45c..ef0770e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -95,6 +95,15 @@ "test", "ideas" ] + }, + { + "login": "pushpinder107", + "name": "pushpinder107", + "avatar_url": "https://avatars3.githubusercontent.com/u/9403361?v=4", + "profile": "https://github.com/pushpinder107", + "contributions": [ + "code" + ] } ], "repoType": "github" diff --git a/README.md b/README.md index 69869e3..5af62d4 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ [![downloads][downloads-badge]][npm-stat] [![MIT License][license-badge]][license] -[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Donate][donate-badge]][donate] [![Code of Conduct][coc-badge]][coc] @@ -273,7 +273,7 @@ Thanks goes to these people ([emoji key][emojis]): | [
Kent C. Dodds](https://kentcdodds.com)
[πŸ’»](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds "Code") [πŸ“–](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds "Documentation") [πŸš‡](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds "Tests") [πŸ‘€](#review-kentcdodds "Reviewed Pull Requests") | [
Conor Hastings](http://conorhastings.com)
[πŸ’»](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings "Code") [πŸ“–](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings "Documentation") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings "Tests") [πŸ‘€](#review-conorhastings "Reviewed Pull Requests") | [
Rogelio Guzman](https://github.com/rogeliog)
[πŸ“–](https://github.com/kentcdodds/match-sorter/commits?author=rogeliog "Documentation") | [
ClaudΓ©ric Demers](http://ced.io)
[πŸ’»](https://github.com/kentcdodds/match-sorter/commits?author=clauderic "Code") [πŸ“–](https://github.com/kentcdodds/match-sorter/commits?author=clauderic "Documentation") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=clauderic "Tests") | [
Kevin Davis](kevindav.us)
[πŸ’»](https://github.com/kentcdodds/match-sorter/commits?author=osfan501 "Code") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=osfan501 "Tests") | [
Denver Chen](https://github.com/nfdjps)
[πŸ’»](https://github.com/kentcdodds/match-sorter/commits?author=nfdjps "Code") [πŸ“–](https://github.com/kentcdodds/match-sorter/commits?author=nfdjps "Documentation") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=nfdjps "Tests") | [
Christian Ruigrok](http://ruigrok.info)
[πŸ›](https://github.com/kentcdodds/match-sorter/issues?q=author%3AChrisRu "Bug reports") [πŸ’»](https://github.com/kentcdodds/match-sorter/commits?author=ChrisRu "Code") [πŸ“–](https://github.com/kentcdodds/match-sorter/commits?author=ChrisRu "Documentation") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| [
Hozefa](https://github.com/hozefaj)
[πŸ›](https://github.com/kentcdodds/match-sorter/issues?q=author%3Ahozefaj "Bug reports") [πŸ’»](https://github.com/kentcdodds/match-sorter/commits?author=hozefaj "Code") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=hozefaj "Tests") [πŸ€”](#ideas-hozefaj "Ideas, Planning, & Feedback") | +| [
Hozefa](https://github.com/hozefaj)
[πŸ›](https://github.com/kentcdodds/match-sorter/issues?q=author%3Ahozefaj "Bug reports") [πŸ’»](https://github.com/kentcdodds/match-sorter/commits?author=hozefaj "Code") [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=hozefaj "Tests") [πŸ€”](#ideas-hozefaj "Ideas, Planning, & Feedback") | [
pushpinder107](https://github.com/pushpinder107)
[πŸ’»](https://github.com/kentcdodds/match-sorter/commits?author=pushpinder107 "Code") | diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 7172dbe..ba4ee0f 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -111,6 +111,19 @@ const tests = { {first: 'not', second: 'not', third: 'not', fourth: 'match'}, ], }, + 'can handle the number 0 as a property value': { + input: [ + [ + {name: 'A', age: 0}, + {name: 'B', age: 1}, + {name: 'C', age: 2}, + {name: 'D', age: 3}, + ], + '0', + {keys: ['age']}, + ], + output: [{name: 'A', age: 0}], + }, 'can handle objected with nested keys': { input: [ [ diff --git a/src/index.js b/src/index.js index cc5b3e2..58f66e2 100644 --- a/src/index.js +++ b/src/index.js @@ -387,7 +387,8 @@ function getItemValues(item, key) { value = item[key] } // concat because `value` can be a string or an array - return value ? [].concat(value) : null + // eslint-disable-next-line + return value != null ? [].concat(value) : null } /**