Socket
Socket
Sign inDemoInstall

vfile-sort

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vfile-sort - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

lib/index.d.ts

9

index.d.ts

@@ -1,8 +0,1 @@

/**
* @template {VFile} F
* @param {F} file
* @returns {F}
*/
export function sort<F extends import('vfile').VFile>(file: F): F
export type VFile = import('vfile').VFile
export type VFileMessage = import('vfile-message').VFileMessage
export {sort} from './lib/index.js'

@@ -1,53 +0,1 @@

/**
* @typedef {import('vfile').VFile} VFile
* @typedef {import('vfile-message').VFileMessage} VFileMessage
*/
var severities = {true: 2, false: 1, null: 0, undefined: 0}
/**
* @template {VFile} F
* @param {F} file
* @returns {F}
*/
export function sort(file) {
file.messages.sort(comparator)
return file
}
/**
* @param {VFileMessage} a
* @param {VFileMessage} b
* @returns {number}
*/
function comparator(a, b) {
return (
check(a, b, 'line') ||
check(a, b, 'column') ||
severities[b.fatal] - severities[a.fatal] ||
compare(a, b, 'source') ||
compare(a, b, 'ruleId') ||
compare(a, b, 'reason') ||
0
)
}
/**
* @param {VFileMessage} a
* @param {VFileMessage} b
* @param {string} property
* @returns {number}
*/
function check(a, b, property) {
return (a[property] || 0) - (b[property] || 0)
}
/**
* @param {VFileMessage} a
* @param {VFileMessage} b
* @param {string} property
* @returns {number}
*/
function compare(a, b, property) {
return String(a[property] || '').localeCompare(b[property] || '')
}
export {sort} from './lib/index.js'
{
"name": "vfile-sort",
"version": "3.0.0",
"version": "3.0.1",
"description": "vfile utility to sort messages by line/column",

@@ -32,2 +32,3 @@ "license": "MIT",

"files": [
"lib/",
"index.d.ts",

@@ -37,23 +38,21 @@ "index.js"

"dependencies": {
"vfile": "^5.0.0",
"vfile-message": "^3.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"vfile": "^5.0.0",
"xo": "^0.39.0"
"xo": "^0.53.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"

@@ -70,7 +69,3 @@ },

"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},

@@ -77,0 +72,0 @@ "remarkConfig": {

@@ -11,17 +11,36 @@ # vfile-sort

Sort [vfile][] messages.
[`vfile`][vfile] utility to sort messages.
* First sorts by line/column: earlier messages come first
* If two messages occurred at the same place, sorts fatal error before
warnings, before info messages
* Otherwise, uses `localeCompare` to compare `source`, `ruleId`, or finally
`reason`
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`sort(file)`](#sortfile)
* [Types](#types)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This is a small package to sort the list of messages.
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`.
## 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](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
[npm][]:
```sh

@@ -31,2 +50,16 @@ npm install vfile-sort

In Deno with [`esm.sh`][esmsh]:
```js
import {sort} from 'https://esm.sh/vfile-sort@3'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {sort} from 'https://esm.sh/vfile-sort@3?bundle'
</script>
```
## Use

@@ -38,3 +71,3 @@

var file = VFile()
const file = VFile()

@@ -52,3 +85,3 @@ file.message('Error!', {line: 3, column: 1})

This package exports the following identifiers: `sort`.
This package exports the identifier [`sort`][api-sort].
There is no default export.

@@ -60,2 +93,23 @@

###### Parameters
* `file` ([`VFile`][vfile])
— file to sort
###### Returns
Sorted file ([`VFile`][vfile]).
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
## Contribute

@@ -105,9 +159,15 @@

[contributing]: https://github.com/vfile/.github/blob/HEAD/contributing.md
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[support]: https://github.com/vfile/.github/blob/HEAD/support.md
[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/HEAD/code-of-conduct.md
[coc]: https://github.com/vfile/.github/blob/main/code-of-conduct.md

@@ -119,1 +179,3 @@ [license]: license

[vfile]: https://github.com/vfile/vfile
[api-sort]: #sortfile
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc