# gulp-sort

> Sort files in stream by path or any custom sort comparator

Latest version **2.0.0** (published 2016-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-sort
pnpm add gulp-sort
yarn add gulp-sort
bun add gulp-sort
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-02-15 |
| First published | 2015-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/gulp-sort) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Gilad Peleg |
| Maintainers | pgilad |
| Keywords | gulpplugin, gulp, sort, paths, order, comparator |

## Links

- npm: https://www.npmjs.com/package/gulp-sort
- Repository: https://github.com/pgilad/gulp-sort
- Homepage: https://github.com/pgilad/gulp-sort#readme
- Issues: https://github.com/pgilad/gulp-sort/issues
- npm.io page: https://npm.io/package/gulp-sort

## Dependencies (1)

- [through2](https://npm.io/package/through2.md) ^2.0.1

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2016-02-15
- 1.1.1 — 2015-05-14
- 1.1.0 — 2015-05-08
- 1.0.1 — 2015-01-27
- 1.0.0 — 2015-01-03

## README

# [gulp](https://github.com/wearefractal/gulp)-sort
> Sort files in stream by path or any custom sort comparator

[![Build Status](http://img.shields.io/travis/pgilad/gulp-sort/master.svg?style=flat)](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>, <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)

---
_Source: https://npm.io/package/gulp-sort · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
