From 5e05aed831e84ba9ef682d06f91debcc1bb31bba Mon Sep 17 00:00:00 2001 From: Pushpinder Date: Sun, 6 May 2018 01:39:41 +0530 Subject: [PATCH 1/3] Fixes issue with filtering with property values of number 0 --- .all-contributorsrc | 9 +++++++++ README.md | 4 ++-- src/__tests__/index.js | 13 +++++++++++++ src/index.js | 2 +- 4 files changed, 25 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 2106678..355a171 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,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] @@ -276,7 +276,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..f70d225 100644 --- a/src/index.js +++ b/src/index.js @@ -387,7 +387,7 @@ function getItemValues(item, key) { value = item[key] } // concat because `value` can be a string or an array - return value ? [].concat(value) : null + return value || value === 0 ? [].concat(value) : null } /** From 425015f26b65bb62a68cbe7b8a46189a2425f6ec Mon Sep 17 00:00:00 2001 From: Pushpinder Date: Mon, 7 May 2018 11:49:30 +0530 Subject: [PATCH 2/3] Fixes null check --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index f70d225..bb0de96 100644 --- a/src/index.js +++ b/src/index.js @@ -387,7 +387,7 @@ function getItemValues(item, key) { value = item[key] } // concat because `value` can be a string or an array - return value || value === 0 ? [].concat(value) : null + return value != null ? [].concat(value) : null } /** From d1415195d8607919f02e17fcd399fc56cb725cc6 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Mon, 7 May 2018 15:06:03 -0600 Subject: [PATCH 3/3] Update index.js --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index bb0de96..58f66e2 100644 --- a/src/index.js +++ b/src/index.js @@ -387,6 +387,7 @@ function getItemValues(item, key) { value = item[key] } // concat because `value` can be a string or an array + // eslint-disable-next-line return value != null ? [].concat(value) : null }