vfile-sort
Advanced tools
Comparing version 2.2.2 to 3.0.0
40
index.js
@@ -1,13 +0,14 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('vfile').VFile} VFile | ||
* @typedef {import('vfile-message').VFileMessage} VFileMessage | ||
*/ | ||
module.exports = sort | ||
var severities = {true: 2, false: 1, null: 0, undefined: 0} | ||
var severities = { | ||
true: 2, | ||
false: 1, | ||
null: 0, | ||
undefined: 0 | ||
} | ||
function sort(file) { | ||
/** | ||
* @template {VFile} F | ||
* @param {F} file | ||
* @returns {F} | ||
*/ | ||
export function sort(file) { | ||
file.messages.sort(comparator) | ||
@@ -17,2 +18,7 @@ return file | ||
/** | ||
* @param {VFileMessage} a | ||
* @param {VFileMessage} b | ||
* @returns {number} | ||
*/ | ||
function comparator(a, b) { | ||
@@ -30,2 +36,8 @@ return ( | ||
/** | ||
* @param {VFileMessage} a | ||
* @param {VFileMessage} b | ||
* @param {string} property | ||
* @returns {number} | ||
*/ | ||
function check(a, b, property) { | ||
@@ -35,4 +47,10 @@ return (a[property] || 0) - (b[property] || 0) | ||
/** | ||
* @param {VFileMessage} a | ||
* @param {VFileMessage} b | ||
* @param {string} property | ||
* @returns {number} | ||
*/ | ||
function compare(a, b, property) { | ||
return (a[property] || '').localeCompare(b[property] || '') | ||
return String(a[property] || '').localeCompare(b[property] || '') | ||
} |
{ | ||
"name": "vfile-sort", | ||
"version": "2.2.2", | ||
"version": "3.0.0", | ||
"description": "vfile utility to sort messages by line/column", | ||
@@ -27,32 +27,34 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": {}, | ||
"dependencies": { | ||
"vfile-message": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^16.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"vfile": "^4.0.0", | ||
"xo": "^0.27.0" | ||
"@types/tape": "^4.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", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"vfile": "^5.0.0", | ||
"xo": "^0.39.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s vfileSort > vfile-sort.js", | ||
"build-mangle": "browserify . -s vfileSort -p tinyify > vfile-sort.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
"prepack": "npm run build && npm run format", | ||
"build": "rimraf \"*.d.ts\" && tsc && 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": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -68,6 +70,6 @@ "tabWidth": 2, | ||
"prettier": true, | ||
"esnext": false, | ||
"ignores": [ | ||
"vfile-sort.js" | ||
] | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
@@ -78,3 +80,8 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true | ||
} | ||
} |
@@ -21,2 +21,5 @@ # vfile-sort | ||
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. | ||
[npm][]: | ||
@@ -31,6 +34,6 @@ | ||
```js | ||
var vfile = require('vfile') | ||
var sort = require('vfile-sort') | ||
import {VFile} from 'vfile' | ||
import {sort} from 'vfile-sort' | ||
var file = vfile() | ||
var file = VFile() | ||
@@ -42,3 +45,3 @@ file.message('Error!', {line: 3, column: 1}) | ||
console.log(file.messages.map(String)) | ||
console.log(file.messages.map(d => String(d))) | ||
// => ['2:2: Another!', '3:1: Error!'] | ||
@@ -49,2 +52,5 @@ ``` | ||
This package exports the following identifiers: `sort`. | ||
There is no default export. | ||
### `sort(file)` | ||
@@ -70,5 +76,5 @@ | ||
[build-badge]: https://img.shields.io/travis/vfile/vfile-sort.svg | ||
[build-badge]: https://github.com/vfile/vfile-sort/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/vfile/vfile-sort | ||
[build]: https://github.com/vfile/vfile-sort/actions | ||
@@ -93,15 +99,15 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-sort.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified/vfile | ||
[chat]: https://github.com/vfile/vfile/discussions | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[contributing]: https://github.com/vfile/.github/blob/master/contributing.md | ||
[contributing]: https://github.com/vfile/.github/blob/HEAD/contributing.md | ||
[support]: https://github.com/vfile/.github/blob/master/support.md | ||
[support]: https://github.com/vfile/.github/blob/HEAD/support.md | ||
[health]: https://github.com/vfile/.github | ||
[coc]: https://github.com/vfile/.github/blob/master/code-of-conduct.md | ||
[coc]: https://github.com/vfile/.github/blob/HEAD/code-of-conduct.md | ||
@@ -108,0 +114,0 @@ [license]: license |
7249
5
56
113
Yes
1
11
+ Addedvfile-message@^3.0.0
+ Added@types/unist@2.0.10(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedvfile-message@3.1.4(transitive)