# vfile-sort

> vfile utility to sort messages by line/column

Latest version **4.0.0** (published 2023-06-10) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2023-06-10 |
| First published | 2015-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 12 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Titus Wormer |
| Maintainers | wooorm |
| Keywords | vfile, vfile-util, util, utility, virtual, file, sort, order, message |

## Links

- npm: https://www.npmjs.com/package/vfile-sort
- Repository: https://github.com/vfile/vfile-sort
- Homepage: https://github.com/vfile/vfile-sort#readme
- Issues: https://github.com/vfile/vfile-sort/issues
- Funding: https://opencollective.com/unified
- npm.io page: https://npm.io/package/vfile-sort

## Dependencies (2)

- [vfile](https://npm.io/package/vfile.md) ^6.0.0
- [vfile-message](https://npm.io/package/vfile-message.md) ^4.0.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2023-06-10
- 3.0.1 — 2023-02-06
- 3.0.0 — 2021-05-05
- 2.2.2 — 2020-03-02
- 2.2.1 — 2019-05-30
- 2.2.0 — 2018-11-22
- 2.1.3 — 2018-11-19
- 2.1.2 — 2018-10-28
- 2.1.1 — 2018-05-03
- 2.1.0 — 2017-07-17
- 2.0.0 — 2016-10-02
- 1.0.0 — 2015-08-16

## README

# vfile-sort

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]

[`vfile`][vfile] utility to sort files or messages.

## Contents

*   [What is this?](#what-is-this)
*   [When should I use this?](#when-should-i-use-this)
*   [Install](#install)
*   [Use](#use)
*   [API](#api)
    *   [`compareFile(a, b)`](#comparefilea-b)
    *   [`compareMessage(a, b)`](#comparemessagea-b)
*   [Types](#types)
*   [Compatibility](#compatibility)
*   [Contribute](#contribute)
*   [License](#license)

## What is this?

This package exposes comparators for vfile files and messages.

## When should I use this?

You can use this right before a reporter is used to give humans a coherent
report.

## Install

This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:

```sh
npm install vfile-sort
```

In Deno with [`esm.sh`][esmsh]:

```js
import {sort} from 'https://esm.sh/vfile-sort@4'
```

In browsers with [`esm.sh`][esmsh]:

```html
<script type="module">
  import {sort} from 'https://esm.sh/vfile-sort@4?bundle'
</script>
```

## Use

```js
import {VFile} from 'vfile'
import {VFileMessage} from 'vfile-message'
import {compareFile, compareMessage} from 'vfile-sort'

console.log(
  [
    new VFileMessage('Error!', {place: {line: 3, column: 1}}),
    new VFileMessage('Another!', {place: {line: 2, column: 2}})
  ]
    .toSorted(compareMessage)
    .map(String)
) //=> ['2:2: Another!', '3:1: Error!']

console.log(
  [
    new VFile(new URL(import.meta.url)),
    new VFile(new URL('.', import.meta.url))
  ]
    .toSorted(compareFile)
    .map((d) => d.path)
) //=> ['/Users/tilde/Projects/oss/vfile-sort/', '/Users/tilde/Projects/oss/vfile-sort/example.js']
```

## API

This package exports the identifiers [`compareFile`][api-compare-file] and
[`compareMessage`][api-compare-message].
There is no default export.

### `compareFile(a, b)`

Compare files (since: `4.0.0`).

###### Parameters

*   `a` ([`VFile`][vfile])
    — file
*   `b` ([`VFile`][vfile])
    — other file

###### Returns

Order (`number`).

### `compareMessage(a, b)`

Compare messages (since: `4.0.0`).

###### Algorithm

It first sorts by line/column: earlier messages come first.
When two messages occurr at the same place, sorts fatal error before
warnings, before info messages.
Finally, it sorts using `localeCompare` on `source`, `ruleId`, or finally
`reason`.

###### Parameters

*   `a` ([`VFile`][vfile])
    — message
*   `b` ([`VFile`][vfile])
    — other message

###### Returns

Order (`number`).

## Types

This package is fully typed with [TypeScript][].
It exports no additional types.

## Compatibility

Projects maintained by the unified collective are compatible with maintained
versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `vfile-sort@^4`,
compatible with Node.js 16.

## Contribute

See [`contributing.md`][contributing] in [`vfile/.github`][health] for ways to
get started.
See [`support.md`][support] for ways to get help.

This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.

## License

[MIT][license] © [Titus Wormer][author]

<!-- Definitions -->

[build-badge]: https://github.com/vfile/vfile-sort/workflows/main/badge.svg

[build]: https://github.com/vfile/vfile-sort/actions

[coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-sort.svg

[coverage]: https://codecov.io/github/vfile/vfile-sort

[downloads-badge]: https://img.shields.io/npm/dm/vfile-sort.svg

[downloads]: https://www.npmjs.com/package/vfile-sort

[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=vfile-sort

[size]: https://bundlejs.com/?q=vfile-sort

[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[backers-badge]: https://opencollective.com/unified/backers/badge.svg

[collective]: https://opencollective.com/unified

[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg

[chat]: https://github.com/vfile/vfile/discussions

[npm]: https://docs.npmjs.com/cli/install

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[esmsh]: https://esm.sh

[typescript]: https://www.typescriptlang.org

[contributing]: https://github.com/vfile/.github/blob/main/contributing.md

[support]: https://github.com/vfile/.github/blob/main/support.md

[health]: https://github.com/vfile/.github

[coc]: https://github.com/vfile/.github/blob/main/code-of-conduct.md

[license]: license

[author]: https://wooorm.com

[vfile]: https://github.com/vfile/vfile

[api-compare-file]: #comparefilea-b

[api-compare-message]: #comparemessagea-b

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