mdast-squeeze-paragraphs
Advanced tools
Comparing version 4.0.0 to 5.0.0
38
index.js
@@ -1,20 +0,32 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('unist').Node} Node | ||
* @typedef {import('unist-util-remove').TestFunctionAnything} TestFunction | ||
*/ | ||
var remove = require('unist-util-remove') | ||
import {remove} from 'unist-util-remove' | ||
module.exports = squeeze | ||
var whiteSpaceOnly = /^\s*$/ | ||
function squeeze(tree) { | ||
/** | ||
* @template {Node} T | ||
* @param {T} tree | ||
* @returns {T} | ||
*/ | ||
export function squeezeParagraphs(tree) { | ||
return remove(tree, {cascade: false}, isEmptyParagraph) | ||
} | ||
// Whether paragraph is empty or composed only of whitespace. | ||
/** | ||
* Whether paragraph is empty or composed only of whitespace. | ||
* | ||
* @type {TestFunction} | ||
*/ | ||
function isEmptyParagraph(node) { | ||
return node.type === 'paragraph' && node.children.every(isEmptyText) | ||
return ( | ||
node.type === 'paragraph' && | ||
// @ts-ignore paragraphs are parents. | ||
node.children.every( | ||
(/** @type {Node} */ node) => | ||
// @ts-ignore texts are literals. | ||
node.type === 'text' && /^\s*$/.test(node.value) | ||
) | ||
) | ||
} | ||
function isEmptyText(node) { | ||
return node.type === 'text' && whiteSpaceOnly.test(node.value) | ||
} |
{ | ||
"name": "mdast-squeeze-paragraphs", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "mdast utility to remove empty paragraphs from a tree", | ||
@@ -33,29 +33,35 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"unist-util-remove": "^2.0.0" | ||
"@types/unist": "^2.0.0", | ||
"unist-util-remove": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"unist-builder": "^2.0.0", | ||
"xo": "^0.26.0" | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"unist-builder": "^3.0.0", | ||
"xo": "^0.39.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run format && npm run test-coverage" | ||
"prepack": "npm run build && npm run format", | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"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 build && npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -71,3 +77,6 @@ "tabWidth": 2, | ||
"prettier": true, | ||
"esnext": false | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
@@ -78,3 +87,8 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true | ||
} | ||
} |
@@ -18,2 +18,5 @@ # mdast-squeeze-paragraphs | ||
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][]: | ||
@@ -28,4 +31,4 @@ | ||
```js | ||
var u = require('unist-builder') | ||
var squeezeParagraphs = require('mdast-squeeze-paragraphs') | ||
import {u} from 'unist-builder' | ||
import {squeezeParagraphs} from 'mdast-squeeze-paragraphs' | ||
@@ -54,2 +57,5 @@ var tree = u('root', [ | ||
This package exports the following identifiers: `squeezeParagraphs`. | ||
There is no default export. | ||
### `squeezeParagraphs(tree)` | ||
@@ -69,2 +75,4 @@ | ||
— [**remark**][remark] plugin wrapper | ||
* [`mdast-util-compact`](https://github.com/syntax-tree/mdast-util-compact) | ||
— make a tree compact | ||
@@ -87,5 +95,5 @@ ## Contribute | ||
[build-badge]: https://img.shields.io/travis/syntax-tree/mdast-squeeze-paragraphs.svg | ||
[build-badge]: https://github.com/syntax-tree/mdast-squeeze-paragraphs/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/syntax-tree/mdast-squeeze-paragraphs | ||
[build]: https://github.com/syntax-tree/mdast-squeeze-paragraphs/actions | ||
@@ -110,5 +118,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-squeeze-paragraphs.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified/syntax-tree | ||
[chat]: https://github.com/syntax-tree/unist/discussions | ||
@@ -119,7 +127,7 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md | ||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md | ||
[support]: https://github.com/syntax-tree/.github/blob/master/support.md | ||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md | ||
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md | ||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md | ||
@@ -126,0 +134,0 @@ [tree]: https://github.com/syntax-tree/unist#tree |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7927
5
37
138
Yes
2
11
+ Added@types/unist@^2.0.0
+ Added@types/unist@2.0.11(transitive)
+ Addedunist-util-is@5.2.1(transitive)
+ Addedunist-util-remove@3.1.1(transitive)
+ Addedunist-util-visit-parents@5.1.3(transitive)
- Removedunist-util-is@4.1.0(transitive)
- Removedunist-util-remove@2.1.0(transitive)
Updatedunist-util-remove@^3.0.0