UNPKG

680 BJavaScriptView Raw
1var through = require('through2');
2
3function defaultComparator(a, b) {
4 return a.path.localeCompare(b.path);
5}
6
7module.exports = function gulpSort(params) {
8 params = params || {};
9 // sort ascending by default
10 var asc = typeof params.asc !== 'undefined' ? asc : true;
11 var comparator = params.comparator || defaultComparator;
12 var files = [];
13
14 return through.obj(function (file, enc, cb) {
15 files.push(file);
16 cb();
17 }, function (cb) {
18 files.sort(comparator);
19 if (!asc) {
20 files.reverse();
21 }
22 files.forEach(function (file) {
23 this.push(file);
24 }, this);
25 cb();
26 });
27};