https://github.com/pgilad/gulp-sort
Sort files in stream by path or any custom sort comparator
https://github.com/pgilad/gulp-sort
gulp gulp-plugin pipeline sort stream utiliy
Last synced: 11 months ago
JSON representation
Sort files in stream by path or any custom sort comparator
- Host: GitHub
- URL: https://github.com/pgilad/gulp-sort
- Owner: pgilad
- License: mit
- Created: 2015-01-01T10:35:54.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2019-02-13T09:27:54.000Z (about 7 years ago)
- Last Synced: 2025-03-28T10:54:09.511Z (12 months ago)
- Topics: gulp, gulp-plugin, pipeline, sort, stream, utiliy
- Language: JavaScript
- Size: 9.77 KB
- Stars: 23
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [gulp](https://github.com/wearefractal/gulp)-sort
> Sort files in stream by path or any custom sort comparator
[](https://travis-ci.org/pgilad/gulp-sort)
## Install
`$ npm install gulp-sort --save-dev`
## Usage
```js
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'));
```
## Options
`gulp-sort` takes in an optional [comparator](#comparator) function, or dictionary with following params:
### asc
Sort ascending. Defaults to true. Specify false to sort descending.
### comparator
Comparator function to use. `comparator(file1, file2)`. Defaults to `localeCompare` of file paths.
### customSortFn
Use `customSortFn` in order to control the sorting yourself (useful for stable sorts).
`customSortFn` signature is as follows:
`customSortFn(, )`
- `files` being the vinyl file objects that were passed in
- `comparator` is the default comparator used, or a custom one that was passed as param
This function is expected to return back the sorted list of files.
## License
MIT © [Gilad Peleg](https://www.giladpeleg.com)