UNPKG

646 BJavaScriptView Raw
1/* eslint-disable complexity */
2'use strict';
3
4const testExpression = /(^|\/|\\)(?:((?:u[0-9a-f]{4,6},?)+)-)(.+)\.svg$/i;
5
6function fileSorter(fileA, fileB) {
7 const hasUnicodeA = testExpression.test(fileA);
8 const hasUnicodeB = testExpression.test(fileB);
9
10 if (hasUnicodeA == hasUnicodeB) {
11 // just compare alphabetically
12 const fileA_ = fileA.substr(0, fileA.lastIndexOf('.'));
13 const fileB_ = fileB.substr(0, fileB.lastIndexOf('.'));
14 return fileA_ < fileB_ ? -1 : 1;
15 } else {
16 // map true to 0, because we want it to be first
17 return (hasUnicodeA ? 0 : 1) - (hasUnicodeB ? 0 : 1);
18 }
19}
20
21module.exports = fileSorter;