Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 3, 2021
1 parent 296673b commit 79a2b71
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const isUrl = require('is-url')
const visit = require('unist-util-visit-parents')
const convert = require('unist-util-is/convert')
import isUrl from 'is-url'
import visit from 'unist-util-visit-parents'
import convert from 'unist-util-is/convert.js'

const isImgExt = (value) => /\.(svg|png|jpg|jpeg|gif)$/.test(value)
const isAbsolutePath = (value) => value.startsWith('/')
Expand All @@ -9,9 +9,7 @@ const isRelativePath = (value) =>
const isImgPath = (value) => isAbsolutePath(value) || isRelativePath(value)
const isInteractive = convert(['link', 'linkReference'])

module.exports = images

function images() {
export default function remarkImages() {
return transform
}

Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"Titus Wormer <[email protected]> (https://wooorm.com)",
"Mathias Beugnon <[email protected]>"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
Expand Down Expand Up @@ -64,7 +67,10 @@
},
"xo": {
"prettier": true,
"esnext": false
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
28 changes: 14 additions & 14 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
var remark = require('remark')
var test = require('tape')
var images = require('.')
import test from 'tape'
import remark from 'remark'
import remarkImages from './index.js'

test('remark-images', function (t) {
test('remarkImages', function (t) {
t.equal(
remark().use(images).processSync('<https://example.com>').toString(),
remark().use(remarkImages).processSync('<https://example.com>').toString(),
'<https://example.com>\n',
'should not support non-image URLs'
)

t.equal(
remark()
.use(images)
.use(remarkImages)
.processSync('https://example.com/example.jpg')
.toString(),
'[![](https://example.com/example.jpg)](https://example.com/example.jpg)\n',
'should support absolute URLs to images'
)

t.equal(
remark().use(images).processSync('/example.jpg').toString(),
remark().use(remarkImages).processSync('/example.jpg').toString(),
'[![](/example.jpg)](/example.jpg)\n',
'should support absolute paths to images'
)

t.equal(
remark().use(images).processSync('./example.jpg').toString(),
remark().use(remarkImages).processSync('./example.jpg').toString(),
'[![](./example.jpg)](./example.jpg)\n',
'should support relative paths to images'
)

t.equal(
remark().use(images).processSync('../example.jpg').toString(),
remark().use(remarkImages).processSync('../example.jpg').toString(),
'[![](../example.jpg)](../example.jpg)\n',
'should support very relative paths to images'
)

t.equal(
remark()
.use(images)
.use(remarkImages)
.processSync('<https://example.com/example.jpg>')
.toString(),
'[![](https://example.com/example.jpg)](https://example.com/example.jpg)\n',
Expand All @@ -47,7 +47,7 @@ test('remark-images', function (t) {

t.equal(
remark()
.use(images)
.use(remarkImages)
.processSync(
'[https://example.com/alpha.jpg](https://example.com/bravo.jpg)'
)
Expand All @@ -58,7 +58,7 @@ test('remark-images', function (t) {

t.equal(
remark()
.use(images)
.use(remarkImages)
.processSync(
'[https://example.com/alpha.jpg][1]\n\n[1]: https://example.com/bravo.jpg'
)
Expand All @@ -69,7 +69,7 @@ test('remark-images', function (t) {

t.equal(
remark()
.use(images)
.use(remarkImages)
.processSync('**https://example.com/alpha.jpg**')
.toString(),
'**[![](https://example.com/alpha.jpg)](https://example.com/alpha.jpg)**\n',
Expand All @@ -78,7 +78,7 @@ test('remark-images', function (t) {

t.equal(
remark()
.use(images)
.use(remarkImages)
.processSync(
'[**https://example.com/alpha.jpg**](https://example.com/bravo.jpg)'
)
Expand Down

0 comments on commit 79a2b71

Please sign in to comment.