Socket
Socket
Sign inDemoInstall

mdast-squeeze-paragraphs

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-squeeze-paragraphs - npm Package Compare versions

Comparing version 5.2.1 to 6.0.0

17

lib/index.d.ts
/**
* Remove empty paragraphs in `tree`.
*
* @template {Node} Tree
* Node type.
* @param {Tree} tree
* @param {Nodes} tree
* Tree to change.
* @returns {Tree extends Paragraph ? Tree | null : Tree}
* Changed tree, or `null` if it was an empty paragraph.
* @returns {undefined}
* Nothing.
*/
export function squeezeParagraphs<Tree extends Node>(
tree: Tree
): Tree extends import('mdast').Paragraph ? Tree | null : Tree
export type Root = import('mdast').Root
export type Content = import('mdast').Content
export type Paragraph = import('mdast').Paragraph
export type Node = Content | Root
export function squeezeParagraphs(tree: Nodes): undefined
export type Nodes = import('mdast').Nodes
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').Paragraph} Paragraph
* @typedef {import('mdast').Nodes} Nodes
*/
/**
* @typedef {Content | Root} Node
*/
import {visit} from 'unist-util-visit'

@@ -16,17 +10,17 @@

*
* @template {Node} Tree
* Node type.
* @param {Tree} tree
* @param {Nodes} tree
* Tree to change.
* @returns {Tree extends Paragraph ? Tree | null : Tree}
* Changed `tree`, or `null` if it was an empty paragraph.
* @returns {undefined}
* Nothing.
*/
export function squeezeParagraphs(tree) {
if (emptyParagraph(tree)) {
// @ts-expect-error: it’s an empty paragraph.
return null
}
visit(tree, function (node, index, parent) {
if (index !== null && parent && emptyParagraph(node)) {
if (
index !== undefined &&
parent &&
node.type === 'paragraph' &&
node.children.every(function (child) {
return child.type === 'text' && /^\s*$/.test(child.value)
})
) {
parent.children.splice(index, 1)

@@ -36,22 +30,2 @@ return index

})
// @ts-expect-error: it’s not an empty paragraph.
return tree
}
/**
* Check if a node is an empty paragraph.
*
* @param {Node} node
* Node to check.
* @returns {boolean}
* Whether `node` was an empty paragraph.
*/
function emptyParagraph(node) {
return (
node.type === 'paragraph' &&
node.children.every(
(child) => child.type === 'text' && /^\s*$/.test(child.value)
)
)
}
{
"name": "mdast-squeeze-paragraphs",
"version": "5.2.1",
"version": "6.0.0",
"description": "mdast utility to remove empty paragraphs from a tree",

@@ -35,4 +35,3 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [

@@ -44,17 +43,15 @@ "lib/",

"dependencies": {
"@types/mdast": "^3.0.0",
"unist-util-visit": "^4.0.0"
"@types/mdast": "^4.0.0",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"tape": "^5.0.0",
"tsd": "^0.25.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^3.0.0",
"xo": "^0.53.0"
"typescript": "^5.0.0",
"unist-builder": "^4.0.0",
"xo": "^0.54.0"
},

@@ -66,22 +63,16 @@ "scripts": {

"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"xo": {
"prettier": true,
"rules": {
"@typescript-eslint/ban-types": "off"
}
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
"remark-preset-wooorm"
]

@@ -92,4 +83,8 @@ },

"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true
}
}

@@ -46,6 +46,6 @@ # mdast-squeeze-paragraphs

This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:
```sh
npm install mdast-util-squeeze-paragraphs
npm install mdast-squeeze-paragraphs
```

@@ -56,3 +56,3 @@

```js
import {squeezeParagraphs} from 'https://esm.sh/mdast-util-squeeze-paragraphs@5'
import {squeezeParagraphs} from 'https://esm.sh/mdast-squeeze-paragraphs@6'
```

@@ -64,3 +64,3 @@

<script type="module">
import {squeezeParagraphs} from 'https://esm.sh/mdast-util-squeeze-paragraphs@5?bundle'
import {squeezeParagraphs} from 'https://esm.sh/mdast-squeeze-paragraphs@6?bundle'
</script>

@@ -72,4 +72,4 @@ ```

```js
import {squeezeParagraphs} from 'mdast-squeeze-paragraphs'
import {u} from 'unist-builder'
import {squeezeParagraphs} from 'mdast-squeeze-paragraphs'

@@ -113,3 +113,3 @@ const tree = u('root', [

Changed `tree` ([`Node`][node]), or `null` if it was an empty paragraph.
Nothing (`undefined`).

@@ -123,7 +123,10 @@ ## Types

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`mdast-squeeze-paragraphs@^6`, compatible with Node.js 16.
## Security

@@ -169,5 +172,5 @@

[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-squeeze-paragraphs.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-squeeze-paragraphs
[size]: https://bundlephobia.com/result?p=mdast-squeeze-paragraphs
[size]: https://bundlejs.com/?q=mdast-squeeze-paragraphs

@@ -174,0 +177,0 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc