Sort files in stream by path or any custom sort comparator
$ npm install gulp-sort --save-dev
var sort = require('gulp-sort'); // default sort gulp.src('./src/js/**/*.js') .pipe(sort()) .pipe(gulp.dest('./build/js')); // pass in a custom comparator function gulp.src('./src/js/**/*.js') .pipe(sort(customComparator)) .pipe(gulp.dest('./build/js')); // sort descending gulp.src('./src/js/**/*.js') .pipe(sort({ asc: false })) .pipe(gulp.dest('./build/js')); // sort with a custom comparator gulp.src('./src/js/**/*.js') .pipe(sort({ comparator: function(file1, file2) { if (file1.path.indexOf('build') > -1) { return 1; } if (file2.path.indexOf('build') > -1) { return -1; } return 0; } })) .pipe(gulp.dest('./build/js')); // sort with a custom sort function var stable = require('stable'); gulp.src('./src/js/**/*.js') .pipe(sort({ customSortFn: function(files, comparator) { return stable(files, comparator); } })) .pipe(gulp.dest('./build/js'));
gulp-sort
takes in an optional comparator function, or dictionary with following params:
Sort ascending. Defaults to true. Specify false to sort descending.
Comparator function to use. comparator(file1, file2)
. Defaults to localeCompare
of file paths.
Use customSortFn
in order to control the sorting yourself (useful for stable sorts).
customSortFn
signature is as follows:
customSortFn(<files>, <comparator>)
files
being the vinyl file objects that were passed incomparator
is the default comparator used, or a custom one that was passed as paramThis function is expected to return back the sorted list of files.
MIT © Gilad Peleg
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4