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 7a821b5 commit 24e00c4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
28 changes: 13 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
'use strict'

var minify = require('rehype-minify-whitespace')({newlines: true})
var visit = require('unist-util-visit-parents')
var embedded = require('hast-util-embedded')
var phrasing = require('hast-util-phrasing')
var whitespace = require('hast-util-whitespace')
var is = require('hast-util-is-element')
var sensitive = require('html-whitespace-sensitive-tag-names')
var repeat = require('repeat-string')

module.exports = format

function format(options) {
import rehypeMinifyWhitespace from 'rehype-minify-whitespace'
import visit from 'unist-util-visit-parents'
import embedded from 'hast-util-embedded'
import phrasing from 'hast-util-phrasing'
import whitespace from 'hast-util-whitespace'
import is from 'hast-util-is-element'
import {whitespaceSensitiveTagNames} from 'html-whitespace-sensitive-tag-names'
import repeat from 'repeat-string'

const minify = rehypeMinifyWhitespace({newlines: true})

export default function rehypeFormat(options) {
var settings = options || {}
var indent = settings.indent || 2
var indentInitial = settings.indentInitial
Expand Down Expand Up @@ -51,7 +49,7 @@ function format(options) {
head = null
}

if (is(node, sensitive)) {
if (is(node, whitespaceSensitiveTagNames)) {
return visit.SKIP
}

Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
Expand All @@ -32,13 +35,12 @@
"hast-util-is-element": "^1.0.0",
"hast-util-phrasing": "^1.0.0",
"hast-util-whitespace": "^1.0.0",
"html-whitespace-sensitive-tag-names": "^1.0.0",
"html-whitespace-sensitive-tag-names": "^2.0.0",
"rehype-minify-whitespace": "^4.0.0",
"repeat-string": "^1.0.0",
"unist-util-visit-parents": "^3.0.0"
},
"devDependencies": {
"bail": "^1.0.0",
"c8": "^7.0.0",
"is-hidden": "^1.0.0",
"negate": "^1.0.0",
Expand All @@ -48,12 +50,12 @@
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"to-vfile": "^6.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-api": "node --conditions development test/index.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test/index.js",
"test": "npm run format && npm run test-coverage"
},
"prettier": {
Expand All @@ -66,8 +68,9 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off",
"unicorn/explicit-length-check": "off",
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/prefer-includes": "off",
Expand Down
38 changes: 18 additions & 20 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
'use strict'

var fs = require('fs')
var path = require('path')
var bail = require('bail')
var test = require('tape')
var rehype = require('rehype')
var vfile = require('to-vfile')
var negate = require('negate')
var hidden = require('is-hidden')
var fmt = require('..')
import fs from 'fs'
import path from 'path'
import test from 'tape'
import rehype from 'rehype'
import vfile from 'to-vfile'
import negate from 'negate'
import hidden from 'is-hidden'
import fmt from '../index.js'

test('format', function (t) {
var root = path.join(__dirname, 'fixtures')
var root = path.join('test', 'fixtures')

fs.readdir(root, function (err, files) {
bail(err)
files = files.filter(negate(hidden))
t.plan(files.length)
const files = fs.readdirSync(root).filter(negate(hidden))

files.forEach(one)
})
t.plan(files.length)

let index = -1
while (++index < files.length) {
one(files[index])
}

function one(fixture) {
var base = path.join(root, fixture)
Expand All @@ -34,10 +32,10 @@ test('format', function (t) {

proc = rehype().use(fmt, config)

proc.process(input, function (err) {
proc.process(input, function (error) {
t.test(fixture, function (t) {
t.plan(3)
t.ifErr(err, 'shouldn’t throw')
t.ifErr(error, 'shouldn’t throw')
t.equal(input.messages.length, 0, 'shouldn’t warn')
t.equal(String(input), String(output), 'should match')
})
Expand Down

0 comments on commit 24e00c4

Please sign in to comment.