Skip to content

Commit 1444c33

Browse files
committed
Refactor to move implementation to lib/
1 parent 7d099ed commit 1444c33

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

index.js

+1-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +1 @@
1-
/**
2-
* @typedef {import('mdast').Root|import('mdast').Content} Node
3-
* @typedef {import('mdast').Paragraph} Paragraph
4-
*/
5-
6-
import {remove} from 'unist-util-remove'
7-
8-
/**
9-
* Remove empty paragraphs in `tree`.
10-
*
11-
* @template {Node} Tree
12-
* @param {Tree} tree
13-
* @returns {Tree extends Paragraph ? Tree | null : Tree}
14-
*/
15-
export function squeezeParagraphs(tree) {
16-
/**
17-
* @param {Node} node
18-
* @returns {boolean}
19-
*/
20-
const filter = (node) =>
21-
Boolean(
22-
node.type === 'paragraph' &&
23-
node.children.every(
24-
(node) => node.type === 'text' && /^\s*$/.test(node.value)
25-
)
26-
)
27-
28-
// @ts-expect-error: `remove` can’t narrow the above test.
29-
return remove(tree, {cascade: false}, filter)
30-
}
1+
export {squeezeParagraphs} from './lib/index.js'

lib/index.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @typedef {import('mdast').Root|import('mdast').Content} Node
3+
* @typedef {import('mdast').Paragraph} Paragraph
4+
*/
5+
6+
import {remove} from 'unist-util-remove'
7+
8+
/**
9+
* Remove empty paragraphs in `tree`.
10+
*
11+
* @template {Node} Tree
12+
* @param {Tree} tree
13+
* @returns {Tree extends Paragraph ? Tree | null : Tree}
14+
*/
15+
export function squeezeParagraphs(tree) {
16+
/**
17+
* @param {Node} node
18+
* @returns {boolean}
19+
*/
20+
const filter = (node) =>
21+
Boolean(
22+
node.type === 'paragraph' &&
23+
node.children.every(
24+
(node) => node.type === 'text' && /^\s*$/.test(node.value)
25+
)
26+
)
27+
28+
// @ts-expect-error: `remove` can’t narrow the above test.
29+
return remove(tree, {cascade: false}, filter)
30+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"main": "index.js",
3636
"types": "index.d.ts",
3737
"files": [
38+
"lib/",
3839
"index.d.ts",
3940
"index.js"
4041
],

0 commit comments

Comments
 (0)