Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 23, 2021
1 parent 1df64be commit 08f972e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 53 deletions.
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
.nyc_output/
.DS_Store
*.log
coverage/
node_modules/
*.log
.DS_Store
mdast-util-to-string.js
mdast-util-to-string.min.js
yarn.lock
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
coverage/
*.json
*.md
mdast-util-to-string.js
mdast-util-to-string.min.js
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict'

module.exports = toString

// Get the text content of a node.
// Prefer the node’s plain-text fields, otherwise serialize its children,
// and if the given value is an array, serialize the nodes in it.
function toString(node) {
export function toString(node) {
return (
(node &&
(node.value ||
Expand Down
40 changes: 16 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,27 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"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",
"devDependencies": {
"browserify": "^17.0.0",
"dtslint": "^4.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 mdastUtilToString -o mdast-util-to-string.js",
"build-mangle": "browserify . -s mdastUtilToString -o mdast-util-to-string.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-types": "dtslint types",
"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,
Expand All @@ -60,18 +56,14 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
},
"ignore": [
"mdast-util-to-string.js",
"types/test.ts"
"types"
]
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
Expand Down
14 changes: 10 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,19 +24,22 @@ npm install mdast-util-to-string
## Use

```js
var unified = require('unified')
var parse = require('remark-parse')
var toString = require('mdast-util-to-string')
import unified from 'unified'
import remarkParse from 'remark-parse'
import {toString} from 'mdast-util-to-string'

var tree = unified()
.use(parse)
.use(remarkParse)
.parse('Some _emphasis_, **importance**, and `code`.')

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

## API

This package exports the following identifiers: `toString`.
There is no default export.

### `toString(node)`

Get the text content of a [node][] or list of nodes.
Expand Down
8 changes: 3 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'
import test from 'tape'
import {toString} from './index.js'

var test = require('tape')
var toString = require('.')

test('mdast-util-to-string', function (t) {
test('toString', function (t) {
t.equal(toString(), '', 'should not fail on a missing node')
t.equal(toString(null), '', 'should not fail on `null` missing node')

Expand Down
8 changes: 2 additions & 6 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"compilerOptions": {
"moduleResolution": "node",
"lib": [
"ES5"
],
"lib": ["ES5"],
"strict": true,
"baseUrl": ".",
"paths": {
"mdast-util-to-string": [
"./index.d.ts"
]
"mdast-util-to-string": ["./index.d.ts"]
}
}
}
2 changes: 1 addition & 1 deletion types/tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "dtslint/dtslint.json",
"extends": "dtslint/dtslint.json",
"rules": {
"semicolon": false,
"whitespace": false
Expand Down

0 comments on commit 08f972e

Please sign in to comment.