gulp-sort
Advanced tools
Comparing version 1.1.1 to 2.0.0
10
index.js
@@ -11,2 +11,3 @@ var through = require('through2'); | ||
var files = []; | ||
var customSortFn; | ||
@@ -21,2 +22,3 @@ if (typeof params === 'function') { | ||
comparator = params.comparator || defaultComparator; | ||
customSortFn = params.customSortFn; | ||
} | ||
@@ -28,3 +30,9 @@ | ||
}, function (cb) { | ||
files.sort(comparator); | ||
if (customSortFn) { | ||
// expect customSortFn to return the files array | ||
files = customSortFn(files, comparator); | ||
} else { | ||
// sort in-place | ||
files.sort(comparator); | ||
} | ||
if (!asc) { | ||
@@ -31,0 +39,0 @@ files.reverse(); |
@@ -5,3 +5,3 @@ { | ||
"repository": "pgilad/gulp-sort", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"license": "MIT", | ||
@@ -29,8 +29,9 @@ "author": { | ||
"dependencies": { | ||
"through2": "^0.6.5" | ||
"through2": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"gulp-util": "^3.0.4", | ||
"mocha": "^2.1.0" | ||
"mocha": "^2.1.0", | ||
"stable": "^0.1.5" | ||
} | ||
} |
@@ -28,3 +28,3 @@ # [gulp](https://github.com/wearefractal/gulp)-sort | ||
.pipe(sort({ | ||
asc: false | ||
asc: false | ||
})) | ||
@@ -47,2 +47,12 @@ .pipe(gulp.dest('./build/js')); | ||
.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')); | ||
``` | ||
@@ -62,4 +72,17 @@ | ||
### customSortFn | ||
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 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](http://giladpeleg.com) |
5037
39
86
3
+ Addedisarray@1.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedisarray@0.0.1(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedthrough2@0.6.5(transitive)
Updatedthrough2@^2.0.1