From d2227739b0ea094e7188285c975b4e72c8f8e46f Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 20 Apr 2021 12:29:27 +0200 Subject: [PATCH] Use ESM --- .gitignore | 3 --- .prettierignore | 3 --- index.js | 8 ++------ package.json | 40 ++++++++++++++++------------------------ readme.md | 10 ++++++++-- test.js | 10 ++++------ 6 files changed, 30 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 2122bb6..735f4af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .DS_Store *.log -.nyc_output/ coverage/ node_modules/ -unist-util-remove-position.js -unist-util-remove-position.min.js yarn.lock diff --git a/.prettierignore b/.prettierignore index b40724f..cebe81f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,2 @@ coverage/ -unist-util-remove-position.js -unist-util-remove-position.min.js -*.json *.md diff --git a/index.js b/index.js index 54287d8..14fe508 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,6 @@ -'use strict' +import {visit} from 'unist-util-visit' -var visit = require('unist-util-visit') - -module.exports = removePosition - -function removePosition(node, force) { +export function removePosition(node, force) { visit(node, remove) return node diff --git a/package.json b/package.json index fc14640..a67fdce 100644 --- a/package.json +++ b/package.json @@ -25,36 +25,32 @@ "Titus Wormer (https://wooorm.com)", "Merlijn Vos " ], + "sideEffects": false, + "type": "module", + "main": "index.js", + "types": "types/index.d.ts", "files": [ - "index.js", - "types/index.d.ts" + "types/index.d.ts", + "index.js" ], - "types": "types/index.d.ts", "dependencies": { - "unist-util-visit": "^2.0.0" + "unist-util-visit": "^3.0.0" }, "devDependencies": { - "browserify": "^17.0.0", - "dtslint": "^4.0.0", - "nyc": "^15.0.0", + "c8": "^7.0.0", "prettier": "^2.0.0", "remark": "^13.0.0", "remark-cli": "^9.0.0", "remark-preset-wooorm": "^8.0.0", "tape": "^5.0.0", - "tinyify": "^3.0.0", - "unist-builder": "^2.0.0", + "unist-builder": "^3.0.0", "xo": "^0.38.0" }, "scripts": { "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "build-bundle": "browserify . -s unistUtilRemovePosition -o unist-util-remove-position.js", - "build-mangle": "browserify . -s unistUtilRemovePosition -o unist-util-remove-position.min.js -p tinyify", - "build": "npm run build-bundle && npm run build-mangle", - "test-types": "dtslint types", - "test-api": "node test", - "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run format && npm run build && npm run test-coverage && npm run test-types" + "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, @@ -66,18 +62,14 @@ }, "xo": { "prettier": true, - "esnext": false, + "rules": { + "no-var": "off", + "prefer-arrow-callback": "off" + }, "ignores": [ - "unist-util-remove-position.js", "types/" ] }, - "nyc": { - "check-coverage": true, - "lines": 100, - "functions": 100, - "branches": 100 - }, "remarkConfig": { "plugins": [ "preset-wooorm" diff --git a/readme.md b/readme.md index 24de76e..e741a92 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,9 @@ ## 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 @@ -21,8 +24,8 @@ npm install unist-util-remove-position ## Use ```js -var remark = require('remark') -var removePosition = require('unist-util-remove-position') +import remark from 'remark' +import {removePosition} from 'unist-util-remove-position' var tree = remark().parse('Some _emphasis_, **importance**, and `code`.') @@ -55,6 +58,9 @@ Yields: ## API +This package exports the following identifiers: `removePosition`. +There is no default export. + ### `removePosition(node[, force])` Remove [`position`][position] fields from [`node`][node]. diff --git a/test.js b/test.js index ef57917..52604d2 100644 --- a/test.js +++ b/test.js @@ -1,9 +1,7 @@ -'use strict' - -var test = require('tape') -var u = require('unist-builder') -var remark = require('remark') -var removePosition = require('.') +import test from 'tape' +import remark from 'remark' +import {u} from 'unist-builder' +import {removePosition} from './index.js' test('removePosition()', function (t) { var empty = {position: undefined}