src/index.js
function matchSorter(items, value, options = {}) {
  // not performing any search/sort if value(search term) is empty
  if (!value) return items

  const {keys, threshold = rankings.MATCHES} = options
  const matchedItems = items.reduce(reduceItemsToRanked, [])
  return matchedItems.sort(sortRankedItems).map(({item}) => item)

  function reduceItemsToRanked(matches, item, index) {
    const {rank, keyIndex, keyThreshold = threshold} = getHighestRanking(
      item,
      keys,
      value,
      options,
    )
    if (rank >= keyThreshold) {
      matches.push({item, rank, index, keyIndex})
    }
    return matches
  }
}
function matchSorter(items, value, options = {}) {
  // not performing any search/sort if value(search term) is empty
  if (!value) return items

  const {keys, threshold = rankings.MATCHES} = options
  const matchedItems = items.reduce(reduceItemsToRanked, [])
  return matchedItems.sort(sortRankedItems).map(({item}) => item)

  function reduceItemsToRanked(matches, item, index) {
    const {rank, keyIndex, keyThreshold = threshold} = getHighestRanking(
      item,
      keys,
      value,
      options,
    )
    if (rank >= keyThreshold) {
      matches.push({item, rank, index, keyIndex})
    }
    return matches
  }
}
function matchSorter ( items , value , options = { } ) { // not performing any search/sort if value(search term) is empty if ( ! value ) return items const { keys , threshold = rankings . MATCHES } = options const matchedItems = items . reduce ( reduceItemsToRanked , [ ] ) return matchedItems . sort ( sortRankedItems ) . map ( ( { item } ) => item ) function reduceItemsToRanked ( matches , item , index ) { const { rank , keyIndex , keyThreshold = threshold } = getHighestRanking ( item , keys , value , options , ) if ( rank >= keyThreshold ) { matches . push ( { item , rank , index , keyIndex } ) } return matches } }
Takes an array of items and a value and returns a new array with the items that match the given value
@param {Array} items - the items to sort
@param {String} value - the value to use for ranking
@param {Object} options - Some options to configure the sorter
@return {Array} - the new sorted array
Takes an array of items and a value and returns a new array with the items that match the given value