vfile-statistics
Advanced tools
Comparing version 1.0.0 to 1.1.0
66
index.js
@@ -1,50 +0,50 @@ | ||
/** | ||
* @author Titus Wormer | ||
* @copyright 2016 Titus Wormer | ||
* @license MIT | ||
* @module vfile-statistics | ||
* @fileoverview Count vfile messages per category. | ||
*/ | ||
'use strict'; | ||
/* Expose. */ | ||
module.exports = statistics; | ||
/** Get stats for a file, list of files, or list of messages. */ | ||
/* Get stats for a file, list of files, or list of messages. */ | ||
function statistics(files) { | ||
var total = 0; | ||
var result = {true: 0, false: 0}; | ||
var result = {true: 0, false: 0, null: 0}; | ||
count(files); | ||
return {fatal: result.true, nonfatal: result.false, total: total}; | ||
return { | ||
fatal: result.true, | ||
nonfatal: result.false + result.null, | ||
warn: result.false, | ||
info: result.null, | ||
total: result.true + result.false + result.null | ||
}; | ||
function count(value) { | ||
var index; | ||
var length; | ||
if (value) { | ||
/* Multiple vfiles */ | ||
if (value[0] && value[0].messages) { | ||
countInAll(value); | ||
/* One vfile / messages */ | ||
} else { | ||
countAll(value.messages || value); | ||
} | ||
} | ||
} | ||
if (!value) { | ||
return; | ||
function countInAll(files) { | ||
var length = files.length; | ||
var index = -1; | ||
while (++index < length) { | ||
count(files[index].messages); | ||
} | ||
} | ||
if (value.messages) { | ||
count(value.messages); | ||
} else if (value[0] && value[0].messages) { | ||
index = -1; | ||
length = value.length; | ||
function countAll(messages) { | ||
var length = messages.length; | ||
var index = -1; | ||
var fatal; | ||
while (++index < length) { | ||
count(value[index].messages); | ||
} | ||
} else { | ||
index = -1; | ||
length = value.length; | ||
while (++index < length) { | ||
result[Boolean(value[index].fatal)]++; | ||
total++; | ||
} | ||
while (++index < length) { | ||
fatal = messages[index].fatal; | ||
result[fatal === null || fatal === undefined ? null : Boolean(fatal)]++; | ||
} | ||
} | ||
} |
{ | ||
"name": "vfile-statistics", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Count vfile messages per category", | ||
@@ -16,23 +16,21 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/wooorm/vfile-statistics", | ||
"bugs": "https://github.com/wooorm/vfile-statistics/issues", | ||
"repository": "https://github.com/vfile/vfile-statistics", | ||
"bugs": "https://github.com/vfile/vfile-statistics/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)" | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"Brendan Abbott <brendan.abbott@temando.com>" | ||
], | ||
"devDependencies": { | ||
"browserify": "^13.0.1", | ||
"browserify": "^14.1.0", | ||
"esmangle": "^1.0.1", | ||
"nyc": "^8.1.0", | ||
"remark-cli": "^1.0.0", | ||
"remark-comment-config": "^4.0.0", | ||
"remark-github": "^5.0.0", | ||
"remark-lint": "^4.0.0", | ||
"remark-validate-links": "^4.0.0", | ||
"nyc": "^11.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"tape": "^4.0.0", | ||
"vfile": "^2.0.0", | ||
"xo": "^0.16.0" | ||
"xo": "^0.18.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . --quiet --frail", | ||
"build-md": "remark . -qfo", | ||
"build-bundle": "browserify index.js --bare -s vfileStatistics > vfile-statistics.js", | ||
@@ -54,2 +52,3 @@ "build-mangle": "esmangle vfile-statistics.js > vfile-statistics.min.js", | ||
"space": true, | ||
"esnext": false, | ||
"ignores": [ | ||
@@ -60,16 +59,6 @@ "vfile-statistics.js" | ||
"remarkConfig": { | ||
"output": true, | ||
"plugins": { | ||
"comment-config": null, | ||
"github": null, | ||
"lint": { | ||
"heading-increment": false, | ||
"list-item-spacing": false | ||
}, | ||
"validate-links": null | ||
}, | ||
"settings": { | ||
"bullet": "*" | ||
} | ||
"plugins": [ | ||
"preset-wooorm" | ||
] | ||
} | ||
} |
# vfile-statistics [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
Count [vfile][] messages per category (fatal, nonfatal, and total). | ||
Count [vfile][] messages per category (fatal, warn, info, nonfatal and total). | ||
## Installation | ||
[npm][npm-install]: | ||
[npm][]: | ||
@@ -16,4 +16,4 @@ ```bash | ||
```js | ||
var vfile = require('vfile'); | ||
var statistics = require('vfile-statistics'); | ||
var vfile = require('vfile'); | ||
@@ -29,2 +29,4 @@ var file = vfile({path: '~/example.md'}); | ||
file.info('This is perfect'); | ||
console.log(statistics(file)); | ||
@@ -36,3 +38,3 @@ ``` | ||
```js | ||
{ fatal: 1, nonfatal: 2, total: 3 } | ||
{ fatal: 1, nonfatal: 3, warn: 2, info: 1, total: 4 } | ||
``` | ||
@@ -47,2 +49,12 @@ | ||
###### Returns | ||
`Object`: | ||
* `fatal`: fatal errors (`fatal: true`) | ||
* `warn`: warning messages (`fatal: false`) | ||
* `info`: informational messages (`fatal: null` or `fatal: undefined`) | ||
* `nonfatal`: warning or info messages | ||
* `total`: all messages | ||
## License | ||
@@ -54,11 +66,11 @@ | ||
[travis-badge]: https://img.shields.io/travis/wooorm/vfile-statistics.svg | ||
[travis-badge]: https://img.shields.io/travis/vfile/vfile-statistics.svg | ||
[travis]: https://travis-ci.org/wooorm/vfile-statistics | ||
[travis]: https://travis-ci.org/vfile/vfile-statistics | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/vfile-statistics.svg | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-statistics.svg | ||
[codecov]: https://codecov.io/github/wooorm/vfile-statistics | ||
[codecov]: https://codecov.io/github/vfile/vfile-statistics | ||
[npm-install]: https://docs.npmjs.com/cli/install | ||
[npm]: https://docs.npmjs.com/cli/install | ||
@@ -69,2 +81,2 @@ [license]: LICENSE | ||
[vfile]: https://github.com/wooorm/vfile | ||
[vfile]: https://github.com/vfile/vfile |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
5288
8
41
77