Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vfile-statistics

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vfile-statistics - npm Package Compare versions

Comparing version 1.1.4 to 2.0.0

index.d.ts

73

index.js

@@ -1,10 +0,29 @@

'use strict'
/**
* @typedef {import('vfile').VFile} VFile
* @typedef {import('vfile-message').VFileMessage} VFileMessage
*
* @typedef Statistics
* @property {number} fatal Fatal errors (`fatal: true`)
* @property {number} warn warning errors (`fatal: false`)
* @property {number} info informational messages (`fatal: null|undefined`)
* @property {number} nonfatal warning + info
* @property {number} total nonfatal + fatal
*/
module.exports = statistics
// Get stats for a file, list of files, or list of messages.
function statistics(files) {
/**
* Get stats for a file, list of files, or list of messages.
*
* @param {Array.<VFile|VFileMessage>|VFile|VFileMessage} [value]
* @returns {Statistics}
*/
export function statistics(value) {
var result = {true: 0, false: 0, null: 0}
count(files)
if (value) {
if (Array.isArray(value)) {
list(value)
} else {
one(value)
}
}

@@ -19,33 +38,27 @@ return {

function count(value) {
if (value) {
if (value[0] && value[0].messages) {
// Multiple vfiles
countInAll(value)
} else {
// One vfile / messages
countAll(value.messages || value)
}
}
}
function countInAll(files) {
var length = files.length
/**
* @param {Array.<VFile|VFileMessage>} value
* @returns {void}
*/
function list(value) {
var index = -1
while (++index < length) {
count(files[index].messages)
while (++index < value.length) {
one(value[index])
}
}
function countAll(messages) {
var length = messages.length
var index = -1
var fatal
/**
* @param {VFile|VFileMessage} value
* @returns {void}
*/
function one(value) {
if ('messages' in value) return list(value.messages)
while (++index < length) {
fatal = messages[index].fatal
result[fatal === null || fatal === undefined ? null : Boolean(fatal)]++
}
result[
value.fatal === undefined || value.fatal === null
? null
: Boolean(value.fatal)
]++
}
}
{
"name": "vfile-statistics",
"version": "1.1.4",
"version": "2.0.0",
"description": "vfile utility to count messages per category: failures, warnings, etc",

@@ -28,32 +28,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 vfileStatistics > vfile-statistics.js",
"build-mangle": "browserify . -s vfileStatistics -p tinyify > vfile-statistics.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": {

@@ -69,6 +71,6 @@ "tabWidth": 2,

"prettier": true,
"esnext": false,
"ignores": [
"vfile-statistics.js"
]
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
},

@@ -79,3 +81,8 @@ "remarkConfig": {

]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

@@ -15,2 +15,5 @@ # vfile-statistics

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][]:

@@ -25,6 +28,6 @@

```js
var vfile = require('vfile')
var statistics = require('vfile-statistics')
import {VFile} from 'vfile'
import {statistics} from 'vfile-statistics'
var file = vfile({path: '~/example.md'})
var file = new VFile({path: '~/example.md'})

@@ -51,2 +54,5 @@ file.message('This could be better')

This package exports the following identifiers: `statistics`.
There is no default export.
### `statistics(file)`

@@ -83,5 +89,5 @@

[build-badge]: https://img.shields.io/travis/vfile/vfile-statistics.svg
[build-badge]: https://github.com/vfile/vfile-statistics/workflows/main/badge.svg
[build]: https://travis-ci.org/vfile/vfile-statistics
[build]: https://github.com/vfile/vfile-statistics/actions

@@ -106,15 +112,15 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-statistics.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

@@ -121,0 +127,0 @@ [license]: license

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