All files filesorter.js

22.22% Statements 2/9
0% Branches 0/8
0% Functions 0/1
22.22% Lines 2/9

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      1x                                 1x  
/* eslint-disable complexity */
'use strict';
 
const testExpression = /(^|\/|\\)(?:((?:u[0-9a-f]{4,6},?)+)-)(.+)\.svg$/i;
 
function fileSorter(fileA, fileB) {
  const hasUnicodeA = testExpression.test(fileA);
  const hasUnicodeB = testExpression.test(fileB);
 
  if (hasUnicodeA == hasUnicodeB) {
    // just compare alphabetically
    const fileA_ = fileA.substr(0, fileA.lastIndexOf('.'));
    const fileB_ = fileB.substr(0, fileB.lastIndexOf('.'));
    return fileA_ < fileB_ ? -1 : 1;
  } else {
    // map true to 0, because we want it to be first
    return (hasUnicodeA ? 0 : 1) - (hasUnicodeB ? 0 : 1);
  }
}
 
module.exports = fileSorter;