Skip to content

Commit 2492695

Browse files
committed
Use ESM
1 parent 73c0587 commit 2492695

File tree

6 files changed

+26
-32
lines changed

6 files changed

+26
-32
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.DS_Store
22
*.log
3-
.nyc_output/
43
coverage/
54
node_modules/
65
yarn.lock

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
coverage/
2-
*.json
32
*.md

index.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
module.exports = toString
2-
3-
function toString(node) {
1+
export function toString(node) {
42
// A root or an element
5-
if ('children' in node) {
6-
return all(node)
7-
}
8-
3+
if ('children' in node) return all(node)
94
return 'value' in node ? node.value : ''
105
}
116

127
function one(node) {
13-
if (node.type === 'text') {
14-
return node.value
15-
}
16-
8+
if (node.type === 'text') return node.value
179
// Ignore things like comments, instruction, cdata.
1810
return node.children ? all(node) : ''
1911
}

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,27 @@
2424
"contributors": [
2525
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
2626
],
27+
"sideEffects": false,
28+
"type": "module",
29+
"main": "index.js",
2730
"files": [
2831
"index.js"
2932
],
3033
"devDependencies": {
31-
"nyc": "^15.0.0",
34+
"c8": "^7.0.0",
3235
"prettier": "^2.0.0",
3336
"remark-cli": "^9.0.0",
3437
"remark-preset-wooorm": "^8.0.0",
3538
"tape": "^5.0.0",
36-
"unist-builder": "^2.0.0",
37-
"xo": "^0.38.0"
39+
"unist-builder": "^3.0.0",
40+
"xo": "^0.39.0"
3841
},
3942
"scripts": {
4043
"format": "remark . -qfo && prettier . --write --loglevel warn && xo --fix",
41-
"test-api": "node test",
42-
"test-coverage": "nyc --reporter lcov tape test.js",
44+
"test-api": "node test.js",
45+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
4346
"test": "npm run format && npm run test-coverage"
4447
},
45-
"nyc": {
46-
"check-coverage": true,
47-
"lines": 100,
48-
"functions": 100,
49-
"branches": 100
50-
},
5148
"prettier": {
5249
"tabWidth": 2,
5350
"useTabs": false,
@@ -58,7 +55,10 @@
5855
},
5956
"xo": {
6057
"prettier": true,
61-
"esnext": false
58+
"rules": {
59+
"no-var": "off",
60+
"prefer-arrow-callback": "off"
61+
}
6262
},
6363
"remarkConfig": {
6464
"plugins": [

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ The resulting text is returned.
1515

1616
## Install
1717

18+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
19+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
20+
1821
[npm][]:
1922

2023
```sh
@@ -24,8 +27,8 @@ npm install xast-util-to-string
2427
## Use
2528

2629
```js
27-
var x = require('xastscript')
28-
var toString = require('xast-util-to-string')
30+
import {x} from 'xastscript'
31+
import {toString} from 'xast-util-to-string'
2932

3033
var tree = x(
3134
'ncx',
@@ -50,6 +53,9 @@ A Christmas CarolCharles Dickens
5053

5154
## API
5255

56+
This package exports the following identifiers: `toString`.
57+
There is no default export.
58+
5359
### `toString(node)`
5460

5561
Utility to get the plain text value of a [*node*][node].

test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var u = require('unist-builder')
5-
var toString = require('.')
1+
import test from 'tape'
2+
import {u} from 'unist-builder'
3+
import {toString} from './index.js'
64

75
test('xast-util-to-string', function (t) {
86
t.deepEqual(

0 commit comments

Comments
 (0)