All files sorter.js

100% Statements 14/14
100% Branches 9/9
100% Functions 3/3
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3019x   19x 56x 56x 56x   56x 5x 49x                 51x 462x 462x 386x 372x     462x        
var naturalSort = require('string-natural-compare')
 
module.exports = (items, column, options = {}) => {
  const { sortFunction, order, alphabet, insensitive } = options
  const caseSensitive = insensitive !== false
  const multi = order === 'desc' ? -1 : 1
 
  if (sortFunction) {
    return items.sort(function (itemA, itemB) {
      return (
        sortFunction(itemA, itemB, {
          valueName: column,
          alphabet,
          caseSensitive,
        }) * multi
      )
    })
  } else {
    return items.sort(function (itemA, itemB) {
      const options = { alphabet }
      if (!alphabet) {
        if (caseSensitive) {
          options.caseInsensitive = true
        }
      }
      return naturalSort('' + itemA.values()[column], '' + itemB.values()[column], options) * multi
    })
  }
}