# All files / src sorter.js

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

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
    30
    311x

    1x
    17x
    17x
    17x

    17x
    1x
    12x

    16x
    239x
    239x
    34x

    205x
    202x

    239x

     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, column, {
              alphabet,
              caseSensitive,
            }) * multi
          )
        })
      } else {
        return items.sort(function (itemA, itemB) {
          let sort = naturalSort
          if (alphabet) {
            sort.alphabet = alphabet
          } else {
            if (caseSensitive) {
              sort = naturalSort.caseInsensitive
            }
          }
          return sort(itemA.values()[column], itemB.values()[column]) * multi
        })
      }
    }