Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 2, 2021
1 parent 8e4c4dc commit 43856ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @typedef {import('unist').Node} Node
*/

var hast2mdast = require('hast-util-to-mdast')
import hast2mdast from 'hast-util-to-mdast'

/**
* Attacher.
Expand All @@ -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?]>}
*/
Expand Down Expand Up @@ -49,6 +49,8 @@ module.exports =
}
)

export default rehypeRemark

/**
* Bridge-mode.
* Runs the destination with the new mdast tree.
Expand All @@ -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: <https://github.com/unifiedjs/unified/pull/141#issuecomment-871239574>
next(err)
next(error)
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (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",
Expand All @@ -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",
Expand All @@ -68,10 +69,10 @@
},
"xo": {
"prettier": true,
"esnext": false,
"ignores": [
"rehype-remark.js"
]
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
16 changes: 7 additions & 9 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
'use strict'

/**
* @typedef {import('./index.js').Options} Options
* @typedef {import('./index.js').Handle} Handle
* @typedef {import('hast').Element} Element
* @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(
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 43856ad

Please sign in to comment.