kentcdodds / match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript
https://npm.im/match-sorter
MIT License
3.73k stars 129 forks source link

Doesn't handle null values #86

Closed sbimochan closed 4 years ago

sbimochan commented 4 years ago

Relevant code or config

const nestedObjList = [
  {name: {first: 'Janice'}},
  {name: {first: null}},
  {name: {first: undefined}},
  {name: {first: 'Jen'}},
]
matchSorter(nestedObjList, 'j', {keys: ['name.first']})

gives: Error: items.reduce is not a function What you did:

I provided null/ undefined values in list

What happened:

Screen Shot 2019-11-23 at 00 04 38

Reproduction repository:

Problem description:

Suggested solution:

kentcdodds commented 4 years ago

It looks like you're calling matchSorter with a variable called rows and I'm guessing that is not an array.

Can you please make a reproduction of your issue?

sbimochan commented 4 years ago

Screenshot is from my main problem and above code is example

dimaqq commented 4 years ago

Works for me match-sorter@4.0.2, babel-compiled, Chrome.

  const nestedObjList = [
    {name: {first: "Janice"}},
    {name: {first: null}},
    {name: {first: undefined}},
    {name: {first: "Jen"}},
  ];
  const res = matchSorter(nestedObjList, "j", {keys: ["name.first"]});
  log.info("sorter", res);

Finds 2 objects.

kentcdodds commented 4 years ago

Looks like this is stale, so I'm going to close it. Good luck :)