Skip to content

Commit 08f972e

Browse files
committed
Use ESM
1 parent 1df64be commit 08f972e

File tree

8 files changed

+35
-53
lines changed

8 files changed

+35
-53
lines changed

Diff for: .gitignore

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
.nyc_output/
1+
.DS_Store
2+
*.log
23
coverage/
34
node_modules/
4-
*.log
5-
.DS_Store
6-
mdast-util-to-string.js
7-
mdast-util-to-string.min.js
85
yarn.lock

Diff for: .prettierignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
coverage/
2-
*.json
32
*.md
4-
mdast-util-to-string.js
5-
mdast-util-to-string.min.js

Diff for: index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
'use strict'
2-
3-
module.exports = toString
4-
51
// Get the text content of a node.
62
// Prefer the node’s plain-text fields, otherwise serialize its children,
73
// and if the given value is an array, serialize the nodes in it.
8-
function toString(node) {
4+
export function toString(node) {
95
return (
106
(node &&
117
(node.value ||

Diff for: package.json

+16-24
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,27 @@
2424
"contributors": [
2525
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
2626
],
27+
"sideEffects": false,
28+
"type": "module",
29+
"main": "index.js",
30+
"types": "types/index.d.ts",
2731
"files": [
28-
"index.js",
29-
"types/index.d.ts"
32+
"types/index.d.ts",
33+
"index.js"
3034
],
31-
"types": "types/index.d.ts",
3235
"devDependencies": {
33-
"browserify": "^17.0.0",
34-
"dtslint": "^4.0.0",
35-
"nyc": "^15.0.0",
36+
"c8": "^7.0.0",
3637
"prettier": "^2.0.0",
3738
"remark-cli": "^9.0.0",
3839
"remark-preset-wooorm": "^8.0.0",
3940
"tape": "^5.0.0",
40-
"tinyify": "^3.0.0",
41-
"xo": "^0.38.0"
41+
"xo": "^0.39.0"
4242
},
4343
"scripts": {
4444
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
45-
"build-bundle": "browserify . -s mdastUtilToString -o mdast-util-to-string.js",
46-
"build-mangle": "browserify . -s mdastUtilToString -o mdast-util-to-string.min.js -p tinyify",
47-
"build": "npm run build-bundle && npm run build-mangle",
48-
"test-api": "node test",
49-
"test-coverage": "nyc --reporter lcov tape test.js",
50-
"test-types": "dtslint types",
51-
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
45+
"test-api": "node test.js",
46+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
47+
"test": "npm run format && npm run test-coverage"
5248
},
5349
"prettier": {
5450
"tabWidth": 2,
@@ -60,18 +56,14 @@
6056
},
6157
"xo": {
6258
"prettier": true,
63-
"esnext": false,
59+
"rules": {
60+
"no-var": "off",
61+
"prefer-arrow-callback": "off"
62+
},
6463
"ignore": [
65-
"mdast-util-to-string.js",
66-
"types/test.ts"
64+
"types"
6765
]
6866
},
69-
"nyc": {
70-
"check-coverage": true,
71-
"lines": 100,
72-
"functions": 100,
73-
"branches": 100
74-
},
7567
"remarkConfig": {
7668
"plugins": [
7769
"preset-wooorm"

Diff for: readme.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
## Install
1414

15+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
16+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
17+
1518
[npm][]:
1619

1720
```sh
@@ -21,19 +24,22 @@ npm install mdast-util-to-string
2124
## Use
2225

2326
```js
24-
var unified = require('unified')
25-
var parse = require('remark-parse')
26-
var toString = require('mdast-util-to-string')
27+
import unified from 'unified'
28+
import remarkParse from 'remark-parse'
29+
import {toString} from 'mdast-util-to-string'
2730

2831
var tree = unified()
29-
.use(parse)
32+
.use(remarkParse)
3033
.parse('Some _emphasis_, **importance**, and `code`.')
3134

3235
console.log(toString(tree)) // => 'Some emphasis, importance, and code.'
3336
```
3437

3538
## API
3639

40+
This package exports the following identifiers: `toString`.
41+
There is no default export.
42+
3743
### `toString(node)`
3844

3945
Get the text content of a [node][] or list of nodes.

Diff for: test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
1+
import test from 'tape'
2+
import {toString} from './index.js'
23

3-
var test = require('tape')
4-
var toString = require('.')
5-
6-
test('mdast-util-to-string', function (t) {
4+
test('toString', function (t) {
75
t.equal(toString(), '', 'should not fail on a missing node')
86
t.equal(toString(null), '', 'should not fail on `null` missing node')
97

Diff for: types/tsconfig.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
{
22
"compilerOptions": {
33
"moduleResolution": "node",
4-
"lib": [
5-
"ES5"
6-
],
4+
"lib": ["ES5"],
75
"strict": true,
86
"baseUrl": ".",
97
"paths": {
10-
"mdast-util-to-string": [
11-
"./index.d.ts"
12-
]
8+
"mdast-util-to-string": ["./index.d.ts"]
139
}
1410
}
1511
}

Diff for: types/tslint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "dtslint/dtslint.json",
2+
"extends": "dtslint/dtslint.json",
33
"rules": {
44
"semicolon": false,
55
"whitespace": false

0 commit comments

Comments
 (0)