Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 1, 2021
1 parent a78396d commit c0f5518
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict'
import {sanitize as hastUtilSanitize, defaultSchema} from 'hast-util-sanitize'

var clean = require('hast-util-sanitize')
export {defaultSchema}

module.exports = sanitize

function sanitize(options) {
export default function rehypeSanitize(options) {
return transformer
function transformer(tree) {
return clean(tree, options)
return hastUtilSanitize(tree, options)
}
}
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,32 @@
"contributors": [
"Titus Wormer <[email protected]> (https://wooorm.com)"
],
"types": "types/index.d.ts",
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"types/index.d.ts",
"index.js"
],
"dependencies": {
"hast-util-sanitize": "^3.0.0"
"hast-util-sanitize": "^4.0.0"
},
"devDependencies": {
"browserify": "^17.0.0",
"c8": "^7.0.0",
"deepmerge": "^4.0.0",
"dtslint": "^4.0.0",
"prettier": "^2.0.0",
"rehype": "^11.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"xo": "^0.36.0"
"xo": "^0.38.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test.js",
"test-types": "dtslint types",
"test": "npm run format && npm run test-coverage && npm run test-types"
"test": "npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand Down
25 changes: 11 additions & 14 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
'use strict'
import test from 'tape'
import rehype from 'rehype'
import merge from 'deepmerge'
import rehypeSanitize, {defaultSchema} from './index.js'

var test = require('tape')
var rehype = require('rehype')
var merge = require('deepmerge')
var gh = require('hast-util-sanitize/lib/github')
var sanitize = require('.')

test('sanitize', function (t) {
test('rehypeSanitize', function (t) {
t.plan(2)

t.test('should work', function (st) {
Expand All @@ -16,9 +13,9 @@ test('sanitize', function (t) {
st.plan(3)

rehype()
.use(sanitize)
.process(input, function (err, file) {
st.ifErr(err, 'shouldn’t fail')
.use(rehypeSanitize)
.process(input, function (error, file) {
st.ifErr(error, 'shouldn’t fail')
st.equal(file.messages.length, 0, 'shouldn’t warn')
st.equal(String(file), String(output), 'should match')
})
Expand All @@ -32,9 +29,9 @@ test('sanitize', function (t) {
st.plan(3)

rehype()
.use(sanitize, merge(gh, {tagNames: ['math', 'mi']}))
.process(input, function (err, file) {
st.ifErr(err, 'shouldn’t fail')
.use(rehypeSanitize, merge(defaultSchema, {tagNames: ['math', 'mi']}))
.process(input, function (error, file) {
st.ifErr(error, 'shouldn’t fail')
st.equal(file.messages.length, 0, 'shouldn’t warn')
st.equal(String(file), String(output), 'should match')
})
Expand Down

0 comments on commit c0f5518

Please sign in to comment.