Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 5, 2021
1 parent 10a82d5 commit 0d00b56
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 48 deletions.
3 changes: 0 additions & 3 deletions .gitignore
@@ -1,8 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
vfile-statistics.js
vfile-statistics.min.js
yarn.lock
3 changes: 0 additions & 3 deletions .prettierignore
@@ -1,5 +1,2 @@
coverage/
vfile-statistics.js
vfile-statistics.min.js
*.json
*.md
10 changes: 4 additions & 6 deletions index.js
@@ -1,9 +1,5 @@
'use strict'

module.exports = statistics

// Get stats for a file, list of files, or list of messages.
function statistics(value) {
export function statistics(value) {
var result = {true: 0, false: 0, null: 0}

if (value) {
Expand Down Expand Up @@ -37,7 +33,9 @@ function statistics(value) {

while (++index < messages.length) {
result[
messages[index].fatal == null ? null : Boolean(messages[index].fatal)
messages[index].fatal === undefined || messages[index].fatal === null
? null
: Boolean(messages[index].fatal)
]++
}
}
Expand Down
37 changes: 12 additions & 25 deletions package.json
Expand Up @@ -25,34 +25,26 @@
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Brendan Abbott <brendan.abbott@temando.com>"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
"devDependencies": {
"browserify": "^17.0.0",
"nyc": "^15.0.0",
"c8": "^7.7.2",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"vfile": "^4.0.0",
"xo": "^0.38.0"
"vfile": "^5.0.0",
"xo": "^0.39.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s vfileStatistics -o vfile-statistics.js",
"build-mangle": "browserify . -s vfileStatistics -o vfile-statistics.min.js -p tinyify",
"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"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
"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 format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -64,15 +56,10 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"eqeqeq": "off",
"no-eq-null": "off",
"unicorn/prefer-optional-catch-binding": "off"
},
"ignores": [
"vfile-statistics.js"
]
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
12 changes: 9 additions & 3 deletions readme.md
Expand Up @@ -12,6 +12,9 @@ Count [vfile][] messages per category (fatal, warn, info, nonfatal and total).

## 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.

[npm][]:

```sh
Expand All @@ -21,10 +24,10 @@ npm install vfile-statistics
## Use

```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'})

file.message('This could be better')
file.message('That could be better')
Expand All @@ -46,6 +49,9 @@ Yields:

## API

This package exports the following identifiers: `statistics`.
There is no default export.

### `statistics(file)`

Pass a [vfile][], list of vfiles, or a list of messages (`file.messages`), get
Expand Down
14 changes: 6 additions & 8 deletions test.js
@@ -1,12 +1,10 @@
'use strict'

var test = require('tape')
var vfile = require('vfile')
var statistics = require('.')
import test from 'tape'
import {VFile} from 'vfile'
import {statistics} from './index.js'

test('statistics()', function (t) {
var file = vfile()
var other = vfile()
var file = new VFile()
var other = new VFile()

t.deepEqual(statistics(), {fatal: 0, nonfatal: 0, warn: 0, info: 0, total: 0})

Expand Down Expand Up @@ -74,7 +72,7 @@ test('statistics()', function (t) {

try {
file.fail('Again')
} catch (_) {}
} catch {}

t.deepEqual(statistics(file), {
fatal: 1,
Expand Down

0 comments on commit 0d00b56

Please sign in to comment.