diff --git a/index.js b/index.js index e16398f..6103658 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ * @typedef {import('unist').Node} Node */ -var hast2mdast = require('hast-util-to-mdast') +import hast2mdast from 'hast-util-to-mdast' /** * Attacher. @@ -19,7 +19,7 @@ var hast2mdast = require('hast-util-to-mdast') * @param destination Optional unified processor. * @param options Options passed to `hast-util-to-mdast`. */ -module.exports = +const rehypeRemark = /** * @type {import('unified').Plugin<[Options?]|[Processor, Options?]>} */ @@ -49,6 +49,8 @@ module.exports = } ) +export default rehypeRemark + /** * Bridge-mode. * Runs the destination with the new mdast tree. @@ -62,10 +64,10 @@ function bridge(destination, options) { function transformer(node, file, next) { destination.run(hast2mdast(node, options), file, done) /** @type {RunCallback} */ - function done(err) { + function done(error) { // @ts-expect-error: `unified` should accept 1 arg for next. // See: - next(err) + next(error) } } } diff --git a/package.json b/package.json index f965fb4..0957f6c 100644 --- a/package.json +++ b/package.json @@ -24,17 +24,18 @@ "contributors": [ "Titus Wormer (https://wooorm.com)" ], + "sideEffects": false, + "type": "module", + "main": "index.js", + "files": [ + "index.js" + ], "dependencies": { "@types/hast": "^2.0.0", "@types/mdast": "^3.0.0", "@types/unist": "^2.0.0", "hast-util-to-mdast": "^7.0.0" }, - "types": "index.d.ts", - "files": [ - "index.js", - "index.d.ts" - ], "devDependencies": { "@types/tape": "^4.0.0", "c8": "^7.0.0", @@ -49,7 +50,7 @@ "type-coverage": "^2.0.0", "typescript": "^4.0.0", "unified": "^9.0.0", - "xo": "^0.36.0" + "xo": "^0.38.0" }, "scripts": { "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", @@ -68,10 +69,10 @@ }, "xo": { "prettier": true, - "esnext": false, - "ignores": [ - "rehype-remark.js" - ] + "rules": { + "no-var": "off", + "prefer-arrow-callback": "off" + } }, "remarkConfig": { "plugins": [ diff --git a/test.js b/test.js index 1f6937d..1a47c4b 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,3 @@ -'use strict' - /** * @typedef {import('./index.js').Options} Options * @typedef {import('./index.js').Handle} Handle @@ -7,12 +5,12 @@ * @typedef {import('hast').Text} Text */ -var test = require('tape') -var unified = require('unified') -var parse = require('rehype-parse') -var markdown = require('remark-stringify') -var html = require('rehype-stringify') -var rehype2remark = require('.') +import test from 'tape' +import unified from 'unified' +import parse from 'rehype-parse' +import markdown from 'remark-stringify' +import html from 'rehype-stringify' +import rehype2remark from './index.js' test('rehype2remark()', function (t) { t.equal( @@ -74,7 +72,7 @@ test('handlers option', function (t) { * @type {Handle} * @param {Element & {tagName: 'div'}} node */ - div: function (h, node) { + div(h, node) { /** @type {Text} */ // @ts-expect-error: there’s one text child. const child = node.children[0]