vfile-sort
vfile utility to sort messages by line/column
Last updated 2 years ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install vfile-sort 
SYNC missed versions from official npm registry.

vfile-sort

Build Coverage Downloads Size Sponsors Backers Chat

vfile utility to sort files or messages.

Contents

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. In Node.js (version 16+), install with npm:

npm install vfile-sort

In Deno with esm.sh:

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

In browsers with esm.sh:

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

Use

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 and compareMessage. There is no default export.

compareFile(a, b)

Compare files (since: 4.0.0).

Parameters
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) — message
  • b (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 in vfile/.github for ways to get started. See support.md for ways to get help.

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

License

MIT © Titus Wormer

Current Tags

  • 4.0.0                                ...           latest (a year ago)

12 Versions

  • 4.0.0                                ...           a year ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           4 years ago
  • 2.2.2                                ...           5 years ago
  • 2.2.1                                ...           5 years ago
  • 2.2.0                                ...           6 years ago
  • 2.1.3                                ...           6 years ago
  • 2.1.2                                ...           6 years ago
  • 2.1.1                                ...           7 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.0                                ...           8 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Total 12
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (8)

© 2010 - cnpmjs.org x YWFE | Home | YWFE