diff --git a/index.js b/index.js index 277f971..194d0ad 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,5 @@ -var visit = require('unist-util-visit') -var whiteSpace = require('hast-util-whitespace') - -module.exports = unwrapImages +import visit from 'unist-util-visit' +import whiteSpace from 'hast-util-whitespace' var unknown = null var containsImage = true @@ -9,7 +7,7 @@ var containsOther = false var splice = [].splice -function unwrapImages() { +export default function remarkUnwrapImages() { return transform } diff --git a/package.json b/package.json index a0ef24f..4de6d59 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,10 @@ "Michele Bertoli ", "José Luis Sandoval Alaguna (https://uzmani.tech/)" ], - "types": "types/index.d.ts", + "sideEffects": false, + "type": "module", + "main": "index.js", "files": [ - "types/index.d.ts", "index.js" ], "dependencies": { diff --git a/test.js b/test.js index 11b2dea..58f75e6 100644 --- a/test.js +++ b/test.js @@ -1,19 +1,23 @@ -var remark = require('remark') -var html = require('remark-html') -var test = require('tape') -var unwrap = require('.') +import test from 'tape' +import remark from 'remark' +import remarkHtml from 'remark-html' +import remarkUnwrapImages from './index.js' -test('remark-unwrap-images', function (t) { +test('remarkUnwrapImages', function (t) { t.equal( - remark().use(unwrap).use(html).processSync('![hi](there.png)').toString(), + remark() + .use(remarkUnwrapImages) + .use(remarkHtml) + .processSync('![hi](there.png)') + .toString(), 'hi\n', 'should unwrap images' ) t.equal( remark() - .use(unwrap) - .use(html) + .use(remarkUnwrapImages) + .use(remarkHtml) .processSync('![alpha](alpha.png) ![bravo](bravo.png)') .toString(), 'alpha\n \nbravo\n', @@ -22,8 +26,8 @@ test('remark-unwrap-images', function (t) { t.equal( remark() - .use(unwrap) - .use(html) + .use(remarkUnwrapImages) + .use(remarkHtml) .processSync('some text ![and](and.png) an image') .toString(), '

some text and an image

\n', @@ -31,21 +35,29 @@ test('remark-unwrap-images', function (t) { ) t.equal( - remark().use(unwrap).use(html).processSync('some text').toString(), + remark() + .use(remarkUnwrapImages) + .use(remarkHtml) + .processSync('some text') + .toString(), '

some text

\n', 'should not unwrap if there are no images' ) t.equal( - remark().use(unwrap).use(html).processSync('[](#remark)').toString(), + remark() + .use(remarkUnwrapImages) + .use(remarkHtml) + .processSync('[](#remark)') + .toString(), '

\n', 'should not unwrap if there are no images in links' ) t.equal( remark() - .use(unwrap) - .use(html) + .use(remarkUnwrapImages) + .use(remarkHtml) .processSync('[![hi](there.png)](#remark)') .toString(), 'hi\n', @@ -54,8 +66,8 @@ test('remark-unwrap-images', function (t) { t.equal( remark() - .use(unwrap) - .use(html) + .use(remarkUnwrapImages) + .use(remarkHtml) .processSync('[![hi](there.png)](#remark)!') .toString(), '

hi!

\n', @@ -64,8 +76,8 @@ test('remark-unwrap-images', function (t) { t.equal( remark() - .use(unwrap) - .use(html) + .use(remarkUnwrapImages) + .use(remarkHtml) .processSync('[![Hello](there.png), world](#remark)') .toString(), '

Hello, world

\n', @@ -74,8 +86,8 @@ test('remark-unwrap-images', function (t) { t.equal( remark() - .use(unwrap) - .use(html) + .use(remarkUnwrapImages) + .use(remarkHtml) .processSync('![hi][image]\n\n[image]: kitten.png') .toString(), 'hi\n',