From 775b154c1c26778642d384fa6a8526dcb00510e0 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 26 Apr 2021 17:12:16 +0200 Subject: [PATCH] Use ESM --- .gitignore | 3 --- .prettierignore | 3 --- index.js | 6 +----- package.json | 32 ++++++++++++-------------------- readme.md | 8 +++++++- test.js | 6 ++---- 6 files changed, 22 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 45b58f4..735f4af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .DS_Store *.log -.nyc_output/ coverage/ node_modules/ -hast-util-whitespace.js -hast-util-whitespace.min.js yarn.lock diff --git a/.prettierignore b/.prettierignore index eeda97d..cebe81f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,2 @@ coverage/ -hast-util-whitespace.js -hast-util-whitespace.min.js -*.json *.md diff --git a/index.js b/index.js index 6198d00..b8bf12c 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,4 @@ -'use strict' - -module.exports = interElementWhiteSpace - -function interElementWhiteSpace(node) { +export function whitespace(node) { var value = node && typeof node === 'object' && node.type === 'text' ? node.value || '' diff --git a/package.json b/package.json index 36d696c..36219fa 100644 --- a/package.json +++ b/package.json @@ -26,27 +26,25 @@ "contributors": [ "Titus Wormer (https://wooorm.com)" ], + "sideEffects": false, + "type": "module", + "main": "index.js", "files": [ "index.js" ], "devDependencies": { - "browserify": "^17.0.0", - "nyc": "^15.0.0", + "c8": "^7.0.0", "prettier": "^2.0.0", "remark-cli": "^9.0.0", "remark-preset-wooorm": "^8.0.0", "tape": "^5.0.0", - "tinyify": "^3.0.0", - "xo": "^0.38.0" + "xo": "^0.39.0" }, "scripts": { "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "build-bundle": "browserify . -s hastUtilWhitespace -o hast-util-whitespace.js", - "build-mangle": "browserify . -s hastUtilWhitespace -o hast-util-whitespace.min.js -p tinyify", - "build": "npm run build-bundle && npm run build-mangle", - "test-api": "node test", - "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run format && npm run build && npm run test-coverage" + "test-api": "node test.js", + "test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", + "test": "npm run format && npm run test-coverage" }, "prettier": { "tabWidth": 2, @@ -58,16 +56,10 @@ }, "xo": { "prettier": true, - "esnext": false, - "ignores": [ - "hast-util-whitespace.js" - ] - }, - "nyc": { - "check-coverage": true, - "lines": 100, - "functions": 100, - "branches": 100 + "rules": { + "no-var": "off", + "prefer-arrow-callback": "off" + } }, "remarkConfig": { "plugins": [ diff --git a/readme.md b/readme.md index aa28be5..e352818 100644 --- a/readme.md +++ b/readme.md @@ -13,6 +13,9 @@ whitespace*][spec]. ## Install +This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): +Node 12+ is needed to use it and it must be `import`ed instead of `require`d. + [npm][]: ```sh @@ -22,7 +25,7 @@ npm install hast-util-whitespace ## Use ```js -var whitespace = require('hast-util-whitespace') +import {whitespace} from 'hast-util-whitespace' whitespace({ type: 'element', @@ -43,6 +46,9 @@ whitespace({ ## API +This package exports the following identifiers: `whitespace`. +There is no default export. + ### `whitespace(node|value)` Check if the given value is [*inter-element whitespace*][spec]. diff --git a/test.js b/test.js index 5a2722d..d617a2f 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var whitespace = require('.') +import test from 'tape' +import {whitespace} from './index.js' test('whitespace', function (t) { t.equal(whitespace(), false, 'should return `false` without node')